📄 components4.java
字号:
/*
* @(#)Components4.java 2007-4-27
* Copyright 2007 AIC. All rights reserved.
*/
package components;
import java.awt.Color;
import javax.swing.*;
/**
* Demonstrating JPanel, JScrollPane, JTabbedPane
*
* Note:
* Their construtors and methods, listeners.
*
* @author Henry Zhu
*/
public class Components4 extends AbstractComponents {
private static final long serialVersionUID = 1L;
private JPanel panel1, panel2;
private JScrollPane scrollPane1, scrollPane2;
private JTabbedPane tabbedPane;
protected void initComponents(Box box) {
String[] items = { "one", "two", "three", "four", "five", "six" };
/* ===================JPanel=================== */
JLabel label = new JLabel("User Name:");
JTextField textField = new JTextField(10);
// # JPanel constructors
panel1 = new JPanel();
// panel1 = new JPanel(new FlowLayout());
// # JPanel methods
panel1.setBackground(Color.GRAY);
panel1.add(label);
panel1.add(textField);
box.add(panel1);
box.add(Box.createVerticalStrut(20));
/* =================JScrollPane================= */
JTextArea textArea = new JTextArea(5, 10);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
// # JScrollPane constructors
scrollPane1 = new JScrollPane(textArea);
// # JScrollPane methods
scrollPane1.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane1.setWheelScrollingEnabled(true);
box.add(scrollPane1);
box.add(Box.createVerticalStrut(20));
/* ============================================ */
ButtonGroup group = new ButtonGroup();
JRadioButton red = new JRadioButton("Red");
JRadioButton green = new JRadioButton("Green");
JRadioButton blue = new JRadioButton("Blue", true);
group.add(red);
group.add(green);
group.add(blue);
panel2 = new JPanel();
panel2.add(red);
panel2.add(green);
panel2.add(blue);
JList list = new JList(items);
list.setVisibleRowCount(5);
list.setFixedCellWidth(200);
list.setFixedCellHeight(20);
scrollPane2 = new JScrollPane(list);
/* =================JTabbedPane================= */
// # JTabbedPane constructors
// tabbedPane = new JTabbedPane();
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
// tabbedPane = new JTabbedPane(JTabbedPane.TOP,
// JTabbedPane.SCROLL_TAB_LAYOUT);
// # JTabbedPane methods
tabbedPane.addTab( "Tab One", null, panel2, "First Panel" );
tabbedPane.addTab( "Tab Two", null, scrollPane2, "First Panel" );
box.add(tabbedPane);
box.add(Box.createVerticalStrut(20));
}
/**
*
* @param title
*/
public Components4(String title) {
super(title);
}
public static void main(String args[]) {
// create Components3 object
String title = "Components: JPanel, JScrollPane, JTabbedPane";
new Components4(title);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -