java - how to set toggle button text value from db on jtable -
How to set the toggle button text value (depending on the database)
Here is the code
Private class checkboxescoder extension extends abstractCellEditor TableCellEditor, ItemListener {Protected JToggleButton Toggle; Private string button value; Public checkboxcode editor () {toggle = new JToggleButton ("off"); Toggle.setHorizontalAlignment (SwingConstants.CENTER); Toggle.addItemListener (this); } Public component getTableCellEditorComponent (JTable table, object value, boolean selected, int row, int column) {buttonValue = (value == null)? "": Value.toString (); Return toggle; } Public object getCellEditorValue () {// System.out.println (buttonValue); Return button value; } @ Override Public Zero ItemState Change (Item Event E) {if (e.getStateChange () == ItemEvent.SELECTED) {toggle.setText ("on!"); Println (buttonValue); } And {toggle.setText ("off"); Println (buttonValue); }}}
Shows an image toggle here but it does not show text.
When I show the text, click on the button and click on the next button, the first button is not visible.
If you know the answer Please share here ..
forgot to set your value toggle button getTableCellEditorComponent {ButtonValue = (value == faucet) before returning from the public component getTableCellEditorComponent (JTable table, object value, selected from Boolean, int row, int column)
To be honest, about what is wrong with returning to from
boolean
to getColumnClass
in the table model for I'm curious to return the
column and assign it to the default renderer and editor ...
In addition to this ... when you return it from the editor, you are ignoring the button value Are ...
public object getCellEditorValue () {// System.out.println (buttonValue); Return button value; }
To be frank, maybe toggle .getText ()
...