Progress Bar Java

Gotta love code from the internet…oh… The code you have violates the singe thread rules of Swing and thus, is a bad example. You have a number of options with SwingWorker. You could publish the progress and use the process method to update the progress bar or you could use a PropertyChangeListener and monitor progress … Read more

How to implement dynamic GUI in swing

only example, everything is hardcoded, for good understanding EDIT: as kleopatra’s noticed, moved JTable#fireTableDataChanged() from ActionListener to the TableModel, amended all ClassNames start with lowerCase import java.awt.*; import java.awt.event.*; import java.util.EventObject; import javax.swing.*; import javax.swing.table.*; public class ComponentTableTest { private JFrame frame; private JTable CompTable = null; private CompTableModel CompModel = null; private JButton addButton … Read more

How to mark JTable cell input as invalid?

The private static class JTable.GenericEditor uses introspection to catch exceptions raised by constructing specific Number subclasses with invalid String values. If you don’t need such generic behavior, consider creating PositiveIntegerCellEditor as a subclass of DefaultCellEditor. Your stopCellEditing() method would be correspondingly simpler. Addendum: Updated to use RIGHT alignment and common error code. Addendum: See also … Read more

How to maintain JTable cell rendering after cell edit

When your editor concludes, the table’s editingStopped() method collects the new value via getCellEditorValue() and uses it to setValueAt() in the model. The model, in turn, should fireTableCellUpdated(), which will invoke the prescribed renderer. Extending the default should be enough to handle Number formatting. In other cases, it may be convenient to use an instance … Read more

How do I get the CellRow when there is an ItemEvent in the JComboBox within the cell

It sounds like you are Using a Combo Box as an Editor. If so, the TableCellEditor method, getTableCellEditorComponent(), includes the row as a parameter. There’s a related example here. Addendum: To change a value in the same row you’ve edited, just have the model return the correct value for the “other column” based on the … Read more