-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJtable.java
More file actions
139 lines (106 loc) · 3.84 KB
/
Jtable.java
File metadata and controls
139 lines (106 loc) · 3.84 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import javafx.scene.control.ComboBox;
import javax.print.attribute.standard.PresentationDirection;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
class Scratch {
public static char ca ='F';
public static void dialog(){
JDialog dialog = new JDialog();
dialog.setSize(400,400);
JButton button = new JButton("sum");
JPanel mainPane = new JPanel();
mainPane.setBounds(50,50,250,250);
mainPane.add(button);
mainPane.setBorder(BorderFactory.createTitledBorder("f(x)"));
dialog.add(mainPane);
dialog.setVisible(true);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Table");
frame.setSize(1920,1280);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
String[] column = new String[9];
String[][] data =new String[30][10];
JTextField search = new JTextField();
JMenuBar menuBar = new JMenuBar();
JMenu fileM = new JMenu("File");
JMenu editM = new JMenu("Edit");
JButton fx = new JButton("F(x)");
menuBar.add(fileM);
menuBar.add(editM);
menuBar.add(fx);
menuBar.add(search);
JTextField contChange = new JTextField();
contChange.setBounds(1100,80,100,20);
JTextArea conArea = new JTextArea();
JScrollPane conPane = new JScrollPane(conArea);
conPane.setBounds(20,550,1200,140);
conArea.setWrapStyleWord(true);
conArea.setEditable(false);
JButton addRow = new JButton("add row");
addRow.setBounds(1100,20,100,20);
JButton addColumn = new JButton("add column");
addColumn.setBounds(1100,50,100,20);
DefaultTableModel tableModel = new DefaultTableModel(data,column);
JTable table = new JTable(tableModel);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(20,20,1000,480);
table.setCellSelectionEnabled(true);
fx.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
dialog();
}
});
addRow.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
tableModel.addRow(new String[]{});
table.setRowSelectionAllowed(true);
}
});
addColumn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if(ca!='Z') {
ca += 1;
tableModel.addColumn(ca);
}
}
});
ListSelectionModel listSelectionModel = table.getSelectionModel();
listSelectionModel.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent listSelectionEvent) {
conArea.setForeground(Color.black);
conArea.setText("");
int n=0;
for(int i=0; i<table.getRowCount();i++)
for (int j = 0; j < table.getColumnCount(); j++) {
if (table.isCellSelected(i, j)) {
conArea.append(table.getColumnName(j) + i + "+");
}
}
}
});
table.editCellAt(table.getSelectedRowCount(),table.getSelectedColumnCount());
tableModel.fireTableDataChanged();
frame.add(scrollPane);
frame.add(addRow);
frame.add(addColumn);
frame.add(contChange);
frame.add(conPane);
frame.setJMenuBar(menuBar);
frame.setVisible(true);
}
}