Dear visitor, welcome to Jabaco - Community.
If this is your first visit here, please read the Help. It explains in detail how this page works.
To use all features of this page, you should consider registering.
Please use the registration form, to register here or read more information about the registration process.
If you are already registered, please login here.
JTable example with sort
Good JTable example with sort
|
Jabaco Source
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
Public Sub Form_Load()
Dim dtm As New DefaultTableModel()
Dim h As NEW JTableHeader
Dim s As JScrollPane
dtm.addColumn("test")
dtm.addColumn("test 2")
dtm.addColumn("test 3")
dtm.setRowCount(200)
dtm.setValueAt("1",0,0)
dtm.setValueAt("2",1,0)
dtm.setValueAt(True,0,1)
Dim jt As New JTable(dtm)
Set h = jt.getTableHeader()
jt.setBounds(0,100,600,600)
jt.setAutoCreateRowSorter(True)
jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
jt.getColumnModel().getColumn(1).setCellEditor(New DEFAULTCellEditor(New JCheckBox()))
jt.getColumnModel().getColumn(2).setCellEditor(New DEFAULTCellEditor(New JComboBox()))
'jt.setContent("box/text", Function() {Return this.getControlProperty("value") ? 'Yes' : 'No'});
Set s = New JScrollPane(jt)
s.setBounds(0,0,500,500)
Me.add(s)
End Sub
|
Thanks! But how do I add the class "DefaultTableModel"?
Just write "javax#swing#table#DefaultTableModel" or add an import statement to the header of your source.
Class javax.swing.table.DefaultTableModel is included in rt.jar of your Java 1.6 environment.
So, rt.jar has to be in the classpath of your project. Use "F1" to check that.
Cheers
A1880
Thanks for the reply!
I tried to write "javax#swing#table#DefaultTableModel" in the Form-code, but it didn't work. Maybe I should write it somewhere else?
Anyway, I did get it to work by pressing F1 and manually select all the components required in the code. Great example code for making tables with sort by clicking the column header!