CellEditor for JXTreeTable does not work - java

I'm trying to implement a JXTreeTable with scrollable cells.
I used custom TableCellRenderer and it looked good, but renderer does not handle events, therefore I added an custom editor to the JXTreeTable.
I thought the cells would be editable once I override isCellEditable() and let it return true anyway but It turned out not. Cells are still not editable, thus I cannot scroll the cells even there are scroll bars.
Any ideas?

Related

How would a dev make a JTable LOOK editable

I'm writing an application that has a JTable, and an edit button that sets the current selected row to be editable. Then once the user is done altering the data, they can click the edit button again (with text that now says "Save") to save the data.
The problem is though, when I set a row to be editable, there isn't a visible difference. I could add some code to the renderer to draw the editable cells a little differently, but I don't know what the proper way to make a cell look editable is. Change the color? Make it look like a JTextField? What's the standard method?
Thanks!
Really this is a user interface design question, not a programming one.
To do what you want you need to supply an appropriate cell renderer with the changes you desire but you will need to decide on your own settings. One option might just be to look at the difference between an editable and non-editable text area and apply those to all the cells on the table. This may be as simple as setting the renderers to disabled for any read-only rows.

A Table like JTreeTable with editable components like ComboBox, TextArea, CheckBox as Rows

Is there any custom plugin(like JTreeTable with editable java components) in java, like in the above image.
I know this can be done by Extending JTreeTable or JXTreeTable Class or using TreeCellEditor etcetera... But, I need a quite exact structure like shown in the above image, Please guide me and Thanks in advance.
Outline, seen here and here, uses the same renderer and editor schema as JTable. For example, to get a column of checkboxes, your RowModel implementation of getColumnClass() should return Boolean.class and your implementation of isCellEditable() should return true for the Logical2 column. I haven't tried it, but DefaultCellEditor, instantiated with a JCheckBox, should work for the combo column.

JXTable and Header Cell Above Scrollbar

JTable and JXTables have a header cell that is generated above the scrollbar. It's a small cell but I would like to use it to render an icon and popup menu. How might I access this header cell?
Thanks
In JXTable, the property to set is the columnControl: basically, it can be any component you like. To keep the functionality of the default, you can subclass ColumnControlButton

Multiline feature in an editable jtable cell

I want to have multiline feature for JTable cells. Wherein the cell automatically expands and shrinks itself when user writes or deletes text in/from cell. I have set columns width, but it doesnt automatically adjust itself according to user's input, rather text beyond the width are not seen at all, but i have a requirement to fix on the width. Can anyone help me with this, to have self adjusting and multiline feature for jtable cell. Would be very thankful.
Thanks in advance.
Several steps:
implement a custom renderer using a JTextArea as rendering component
implement a custom editor using a JTextArea inside a JScrollPane as editing component
add logic (aka: TableModelListener) which updates JTable's individual rowHeight based on the renderer's preferred size on receiving a change notification

Remove Renderer from a JTable

I have a JTable with a Renderer written by myself. When I set the JTable disabled, I want it to be painted in gray, and with the current Renderer that's not possible. That's why I want to remove the renderer when I set the JTable disabled, and then when enabled set it again.
Is that possible, or may I take a different solution?
Before setting your custom renderer, get the default renderer from the JTable. Store it in a reference for later use. Now set your custom renderer to JTable.
Before disabling the table, set the default one and when you enable it set the custom one.
I hope this should work for you.
You can set a new DefaultTableRenderer(). It should be possible too in your Renderer. Alternatively you could extend DefaultTableRenderer.
use JXTable (from the SwingX project) - its renderers respect the table enablement automatically
Edit
on reading again:
I have a JTable with a Renderer written by myself. When I set the
JTable disabled, I want it to be painted in gray, and with the current
Renderer that's not possible
why isn't that possible? In your custom renderer simply query the table enablement and configure its state accordingly
public Component getTableCellRendererComponent(...) {
...
myRenderingComponent.setEnabled(table.isEnabled());
return myRenderingComponent;
}
You can check if the table is enabled when the renderer component is returned. You can then set a state variable in the renderer which will render the cell differently when it is disabled than when it is enabled. This approach also makes it possible to allow for other states - I have a renderer that allows for different "profiles" depending on values in a specific column.

Categories

Resources