List of GUI Properties in Swing

How do you create a property list component in Swing? I mean look like in this or this image. Is it just a custom JTable component or a custom component?

+4
source share
3 answers

It is definitely a table-based component, but its creation is not trivial. I suggest you use an existing one. Here is a link to a free and very good one: http://www.l2fprod.com/common/

+2
source

if you do not want to code it yourself, JideSoft has a component called PropertyPane. This is part of their Jide Grids package, which costs $ 299.99.

I did not use this particular component, but from experience I can say that their components are very well polished and made.

web start demo of all their components

Hth

Koen

+2
source

Here is a basic example that you could further customize for your use:

import java.awt.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public class TablePropertyEditor extends JFrame { public TablePropertyEditor() { String[] columnNames = {"Type", "Value"}; Object[][] data = { {"String", "I'm a string"}, {"Date", new Date()}, {"Integer", new Integer(123)}, {"Double", new Double(123.45)}, {"Boolean", Boolean.TRUE} }; JTable table = new JTable(data, columnNames) { private Class editingClass; public TableCellRenderer getCellRenderer(int row, int column) { editingClass = null; int modelColumn = convertColumnIndexToModel(column); if (modelColumn == 1) { Class rowClass = getModel().getValueAt(row, modelColumn).getClass(); return getDefaultRenderer( rowClass ); } else return super.getCellRenderer(row, column); } public TableCellEditor getCellEditor(int row, int column) { editingClass = null; int modelColumn = convertColumnIndexToModel(column); if (modelColumn == 1) { editingClass = getModel().getValueAt(row, modelColumn).getClass(); return getDefaultEditor( editingClass ); } else return super.getCellEditor(row, column); } // This method is also invoked by the editor when the value in the editor // component is saved in the TableModel. The class was saved when the // editor was invoked so the proper class can be created. public Class getColumnClass(int column) { return editingClass != null ? editingClass : super.getColumnClass(column); } }; table.setPreferredScrollableViewportSize(table.getPreferredSize()); JScrollPane scrollPane = new JScrollPane( table ); getContentPane().add( scrollPane ); } public static void main(String[] args) { TablePropertyEditor frame = new TablePropertyEditor(); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setLocationRelativeTo( null ); frame.setVisible(true); } } 
+2
source

All Articles