JTable Cell Renderer

Is your renderer ever even used? You make it the default renderer for cells containing String, but have you overloaded your model’s getColumnClass method so that it knows that some of the cells hold Strings? So first I’d use println statements to see if the renderer is even being called and if not, I’d override … Read more

how to add different JComboBox items in a Column of a JTable in Swing

example on java2s.com looks like as works and correctly, then for example (I harcoded JComboBoxes for quick example, and add/change for todays Swing) import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.UIManager.LookAndFeelInfo; import javax.swing.table.*; public class EachRowEditorExample extends JFrame { private static final long serialVersionUID = 1L; public EachRowEditorExample() { super(“EachRow Editor Example”); try { for … Read more

How to merge cell in DefaultTableModel/JTable?

MultiSpanCellTableExample demonstrates how to merge cells by creating a custom TableUI. There seem to be a problem in this example that causes StackOverflowError, at least in Java 6. To fix this, inside AttributiveCellTableModel.setDataVector() replace: setColumnIdentifiers(columnNames); with: this.columnIdentifiers = columnNames; IE: public void setDataVector(Vector newData, Vector columnNames) { if (newData == null) throw new IllegalArgumentException( “setDataVector() … Read more

Adding multiple JProgressBar to TableColumn of JTable

basically there are two ways move with JProgressBar by using SwingWorker and Runnable#Thread, example for SwingWorker import java.awt.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; public class TableCellProgressBar { private String[] columnNames = {“String”, “ProgressBar”}; private Object[][] data = {{“dummy”, 100}}; private DefaultTableModel model = new DefaultTableModel(data, columnNames) { private static final long serialVersionUID = 1L; … Read more

TableCellRenderer and how to refresh Cell background without using JTable.repaint()

The issue occurs when you change the selected item. You have some implicit interaction between your combobox and you table (the selected item of the combo box influences the way the table is painted). When the comboboxpopup is hidden, it automatically triggers a repaint of the hovered area (the RepaintManager will only repaint the hovered … 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 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