You are not logged in.

sedrok

Beginner

  • "sedrok" started this thread

Posts: 9

Date of registration: Apr 26th 2009

  • Send private message

1

Monday, April 12th 2010, 3:17pm

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

Tobias

Beginner

  • "Tobias" is male

Posts: 12

Date of registration: Mar 31st 2010

Location: Sweden

Occupation: Programmer / Network tech

  • Send private message

2

Thursday, April 15th 2010, 2:29pm

Thanks! But how do I add the class "DefaultTableModel"?

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

3

Thursday, April 15th 2010, 3:28pm

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

Tobias

Beginner

  • "Tobias" is male

Posts: 12

Date of registration: Mar 31st 2010

Location: Sweden

Occupation: Programmer / Network tech

  • Send private message

4

Friday, April 16th 2010, 10:57pm

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!

Rate this thread
WoltLab Burning Board