-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
64 lines (63 loc) · 2.17 KB
/
Test.java
File metadata and controls
64 lines (63 loc) · 2.17 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication2;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.table.*;
public class Test {
public static void main(String args[]) {
JFrame jf = new JFrame("Cell Combine Table");
JTable cTable = getTable2();
jf.getContentPane().add(new JScrollPane(cTable));
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(500, 500);
jf.setVisible(true);
}
private static CombineTable getTable1() {
String[][] datas = new String[10][6];
for (int i = 0; i < datas.length; i++) {
String[] data = datas[i];
for (int j = 0; j < data.length; j++) {
data[j] = ""; }
data[0] = String.valueOf((int) (i / 3));
}
ArrayList<Integer> combineColumns = new ArrayList<Integer>();
combineColumns.add(0);
CombineData m = new CombineData(datas, combineColumns);
DefaultTableModel tm = new DefaultTableModel(datas, new String[]{"1", "2", "3", "4", "5"});
CombineTable cTable = new CombineTable(m, tm);
TableColumn column = cTable.getColumnModel().getColumn(0);
column.setCellRenderer(new CombineColumnRender());
column.setWidth(50);
column.setMaxWidth(50);
column.setMinWidth(50);
cTable.setCellSelectionEnabled(true);
return cTable;
}
private static CombineTable getTable2() {
String[][] datas = new String[10][6];
for (int i = 0; i < datas.length; i++) {
String[] data = datas[i];
for (int j = 0; j < data.length; j++) {
data[j] = ""; }
data[0] = String.valueOf((int) (i / 4));
data[1] = String.valueOf((int) (i / 2));
}
CombineData m = new CombineData(datas, 0, 1);
DefaultTableModel tm = new DefaultTableModel(datas, new String[]{"1", "2", "3", "4", "5"});
CombineTable cTable = new CombineTable(m, tm);
TableColumnModel columnModel = cTable.getColumnModel();
for (Integer integer : m.combineColumns) {
TableColumn column = columnModel.getColumn(integer);
column.setCellRenderer(new CombineColumnRender());
column.setWidth(50);
column.setMaxWidth(50);
column.setMinWidth(50);
}
cTable.setCellSelectionEnabled(true);
return cTable;
}
}