📄 test.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Test extends JApplet {
JDesktopPane desktopPane = new JDesktopPane();
JInternalFrame jif = new JInternalFrame(
"Internal Frame ", // title
true, // resizable
true, // closable
true, // maximizable
true); // iconifiable
JScrollBar scrollbar = new JScrollBar();
JSlider slider = new JSlider();
JToolBar toolbar = new JToolBar();
JTree tree = new JTree();
public void init() {
Container contentPane = getContentPane();
jif.setPreferredSize(new Dimension(550, 450));
jif.getContentPane().setLayout(new FlowLayout());
jif.getContentPane().add(new ComponentPanel());
desktopPane.setLayout(new FlowLayout());
desktopPane.add(jif);
contentPane.add(new ControlPanel(), BorderLayout.NORTH);
contentPane.add(desktopPane, BorderLayout.CENTER);
}
class ComponentPanel extends JPanel {
public ComponentPanel() {
JPanel panel = new JPanel();
setLayout(new BorderLayout());
add(toolbar, BorderLayout.NORTH);
add(panel, BorderLayout.CENTER);
panel.add(scrollbar);
panel.add(slider);
panel.add(new JScrollPane(tree));
tree.setPreferredSize(new Dimension(200,100));
toolbar.add(new JButton("button"));
}
}
class ControlPanel extends JPanel {
JCheckBox rollover = new JCheckBox(
"JToolBar.rollover");
JCheckBox palette = new JCheckBox(
"JInternalFrame.palette");
JCheckBox filled = new JCheckBox(
"JSlider.isFilled");
JCheckBox freeStanding = new JCheckBox(
" JScrollBar.freeStanding");
JRadioButton none = new JRadioButton("none");
JRadioButton horizontal = new JRadioButton("horizontal");
JRadioButton angled = new JRadioButton("angled");
public ControlPanel() {
ActionListener checkBoxListener =
new CheckBoxListener();
ActionListener radioButtonListener =
new RadioButtonListener();
palette.addActionListener(checkBoxListener);
filled.addActionListener(checkBoxListener);
rollover.addActionListener(checkBoxListener);
freeStanding.addActionListener(checkBoxListener);
none.addActionListener(radioButtonListener);
horizontal.addActionListener(radioButtonListener);
angled.addActionListener(radioButtonListener);
ButtonGroup group = new ButtonGroup();
group.add(none);
group.add(horizontal);
group.add(filled);
none.setSelected(true);
freeStanding.setSelected(true);
add(palette);
add(filled);
add(rollover);
add(freeStanding);
add(Box.createHorizontalStrut(10));
add(new JLabel("Tree: "));
add(none);
add(horizontal);
add(angled);
}
class RadioButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JRadioButton rb = (JRadioButton)e.getSource();
if(rb == none) {
tree.putClientProperty(
"JTree.lineStyle", "None");
}
if(rb == horizontal) {
tree.putClientProperty(
"JTree.lineStyle", "Horizontal");
}
if(rb == angled) {
tree.putClientProperty(
"JTree.lineStyle", "Angled");
}
tree.repaint();
}
}
class CheckBoxListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JCheckBox cb = (JCheckBox)e.getSource();
if(cb == palette) {
palette.putClientProperty(
"JInternalFrame.isPalette",
new Boolean(cb.isSelected()));
jif.revalidate();
}
else if(cb == filled) {
slider.putClientProperty(
"JSlider.isFilled",
new Boolean(cb.isSelected()));
slider.repaint();
}
else if(cb == rollover) {
toolbar.putClientProperty(
"JToolBar.isRollover",
new Boolean(cb.isSelected()));
toolbar.repaint();
}
else if(cb == freeStanding) {
scrollbar.putClientProperty(
"JScrollBar.isFreeStanding",
new Boolean(cb.isSelected()));
scrollbar.repaint();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -