📄 test.java
字号:
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class Test extends JApplet {
Component strut = Box.createHorizontalStrut(50);
public Test() {
Container contentPane = getContentPane();
//Box box = new Box(BoxLayout.X_AXIS);
JPanel box = new JPanel();
box.setLayout(new GridLayout(2,1));
box.add(new JButton("button 1"));
box.add(strut);
box.add(new JButton("button 2"));
contentPane.setLayout(new FlowLayout());
contentPane.add(box);
}
public void paint(Graphics g) {
super.paint(g);
System.out.println("strut width: " +
strut.getSize().width);
}
public static void main(String args[]) {
final JFrame f = new JFrame();
JApplet applet = new Test();
applet.init();
f.setContentPane(applet.getContentPane());
f.setBounds(100,100,308,199);
f.setTitle("An Application");
f.setVisible(true);
f.setDefaultCloseOperation(
WindowConstants.DISPOSE_ON_CLOSE);
f.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -