📄 test.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.util.*;
public class Test extends JFrame {
JTable table = new JTable(
new AbstractTableModel() {
public int getRowCount() { return 10; }
public int getColumnCount() { return 10; }
public Object getValueAt(int row, int col) {
return "(" + Integer.toString(row) + "," +
Integer.toString(col) + ")";
}
});
public Test() {
Container cp = getContentPane();
cp.add(new JScrollPane(table), BorderLayout.CENTER);
cp.add(new ControlPanel(), BorderLayout.NORTH);
}
class ControlPanel extends JPanel {
private JSlider slider = new JSlider(
JSlider.HORIZONTAL,0,100,
table.getColumnModel().getColumnMargin());
private JLabel label = new JLabel();
public ControlPanel() {
add(new JLabel("Column Margin:"));
add(slider);
add(label);
label.setText(
Integer.toString(
table.getColumnModel().getColumnMargin()));
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
table.getColumnModel().setColumnMargin(
slider.getValue());
}
});
table.getColumnModel().addColumnModelListener(
new TableColumnModelListener() {
public void columnMarginChanged(ChangeEvent e) {
TableColumnModel m = table.getColumnModel();
label.setText(
Integer.toString(m.getColumnMargin()));
}
// unfortunately, Swing does not have many
// event adapter classes ...
public void columnAdded(TableColumnModelEvent e) {
}
public void columnMoved(TableColumnModelEvent e) {
}
public void columnRemoved(
TableColumnModelEvent e) {
}
public void columnSelectionChanged(
ListSelectionEvent e) {
}
});
}
}
public static void main(String args[]) {
GJApp.launch(new Test(),
"Column Margins",150,150,500,200);
}
}
class GJApp extends WindowAdapter {
static private JPanel statusArea = new JPanel();
static private JLabel status = new JLabel(" ");
static private ResourceBundle resources;
public static void launch(final JFrame f, String title,
final int x, final int y,
final int w, int h) {
launch(f,title,x,y,w,h,null);
}
public static void launch(final JFrame f, String title,
final int x, final int y,
final int w, int h,
String propertiesFilename) {
f.setTitle(title);
f.setBounds(x,y,w,h);
f.setVisible(true);
statusArea.setBorder(BorderFactory.createEtchedBorder());
statusArea.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
statusArea.add(status);
status.setHorizontalAlignment(JLabel.LEFT);
f.setDefaultCloseOperation(
WindowConstants.DISPOSE_ON_CLOSE);
if(propertiesFilename != null) {
resources = ResourceBundle.getBundle(
propertiesFilename, Locale.getDefault());
}
f.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
}
static public JPanel getStatusArea() {
return statusArea;
}
static public void showStatus(String s) {
status.setText(s);
}
static Object getResource(String key) {
if(resources != null) {
return resources.getString(key);
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -