Java 带GridLayout的滚动条(1,1)
我正在用Swing编写一个Java程序,但我遇到了一些麻烦。我可以将滚动条添加到我的文本区域:Java 带GridLayout的滚动条(1,1),java,swing,jscrollpane,layout-manager,jtextarea,Java,Swing,Jscrollpane,Layout Manager,Jtextarea,我正在用Swing编写一个Java程序,但我遇到了一些麻烦。我可以将滚动条添加到我的文本区域: //Text area public static JTextArea output = new JTextArea("======================== The Outputs HERE ================================"); // JBouton private JButton bouton = new JButton(
//Text area
public static JTextArea output = new JTextArea("======================== The Outputs HERE ================================");
// JBouton
private JButton bouton = new JButton();
private JButton tpBouton = new JButton("TP 205");
// JLabel
private JLabel label = new JLabel("TP DE 205");
public static JLabel initialState = new JLabel("TEST");
public static JLabel state = new JLabel("");
public static JLabel tableShow = new JLabel("Entrer l'element a rechercher : ");
public static JLabel finalState = new JLabel("");
private JLabel explicitText = new JLabel();
// JTextField
private JFormattedTextField input = new JFormattedTextField(NumberFormat.getIntegerInstance());
//JTextField input = new JTextField("Choisir l'element a rechercher ...");
// JPanel
JPanel mainBGRadio = new JPanel();
JPanel secondBGRadio = new JPanel();
JPanel b7 = new JPanel();
JPanel main = new JPanel();
JPanel container = new JPanel();
JPanel outPutField = new JPanel();
// Ensemble
private Ensemble set = new Ensemble();
// JRadioButton
// for the main group
private JRadioButton lookup = new JRadioButton("Look Up");
private JRadioButton insert = new JRadioButton("Insert");
private JRadioButton delete = new JRadioButton("Delete");
private JRadioButton difference = new JRadioButton("Difference");
private JRadioButton intersection = new JRadioButton("Intersection");
private JRadioButton union = new JRadioButton("Union");
// for the second group
private JRadioButton sortedList = new JRadioButton("liste Trie");
private JRadioButton simpleList = new JRadioButton("liste Simple");
private JRadioButton doubleList = new JRadioButton("liste Avec Doublons");
private JRadioButton simpleVector = new JRadioButton("vecteur Simple");
private JRadioButton sortedVector = new JRadioButton("vecteur Trie");
private JRadioButton booleanVector = new JRadioButton("vecteur Boolean");
// JButtonGroup
// some bouton group
private ButtonGroup mainBG = new ButtonGroup();
private ButtonGroup secondBG = new ButtonGroup();
// ArrayList
private ArrayList<JRadioButton> radioList = new ArrayList(){{
add(lookup);
add(insert);
add(delete);
add(union);
add(intersection);
add(difference);
}};
private ArrayList<JRadioButton> radioFunctionList = new ArrayList(){{
add(sortedList);
add(doubleList);
add(simpleList);
add(simpleVector);
add(sortedVector);
add(booleanVector);
}};
// Font
Font font = new Font("ubuntu", Font.BOLD, 45);
Font explicitFont = new Font("ubuntu", Font.BOLD, 15);
Font stateFont = new Font("ubuntu", Font.BOLD, 25);
Font textareaFont = new Font("ubuntu", Font.ITALIC, 19);
public Fenetre(){
}
/**
* this is the main window with all its contains element
*/
public void montrer(){
// window Params
this.setTitle("TP 205");
this.setSize(800, 800);
this.setLocationRelativeTo(null);
// bouton configuration
bouton.setText("Simuler");
bouton.addActionListener(new BtnClass());
tpBouton.addActionListener(new BtnClass());
tpBouton.setBackground(Color.BLACK);
tpBouton.setFont(explicitFont);
tpBouton.setForeground(Color.WHITE);
// JLabel configuration
explicitText.setText("Bienvenur sur notre tp de 205");
label.setFont(font);
explicitText.setFont(explicitFont);
explicitText.setForeground(Color.WHITE);
label.setForeground(Color.WHITE);
state.setForeground(Color.WHITE);
state.setFont(stateFont);
initialState.setForeground(Color.WHITE);
initialState.setFont(stateFont);
finalState.setForeground(Color.WHITE);
finalState.setFont(stateFont);
// input configuration
input.setFont(explicitFont);
input.setPreferredSize(new Dimension(150, 30));
input.setForeground(Color.BLACK);
input.setMaximumSize(new Dimension(Integer.MAX_VALUE, input.getMinimumSize().height));
output.setFont(textareaFont);
output.setWrapStyleWord(true);
output.setLineWrap(true);
JScrollPane scrool = new JScrollPane();
scrool.setBorder(BorderFactory.createTitledBorder("LIONEL"));
scrool.setViewportView(output);
// layout configuration
JPanel b1 = new JPanel();
b1.setLayout(new BoxLayout(b1, BoxLayout.LINE_AXIS));
b1.add(label);
JPanel b2 = new JPanel();
b2.setLayout(new BoxLayout(b2, BoxLayout.LINE_AXIS));
b2.add(explicitText);
JPanel b3 = new JPanel();
b3.setLayout(new BoxLayout(b3, BoxLayout.LINE_AXIS));
b3.add(tpBouton);
b3.add(bouton);
JPanel b4 = new JPanel();
b4.setLayout(new BoxLayout(b4, BoxLayout.LINE_AXIS));
b4.add(state);
JPanel b5 = new JPanel();
b5.setLayout(new BoxLayout(b5, BoxLayout.LINE_AXIS));
b5.add(finalState);
JPanel b6 = new JPanel();
b6.setLayout(new BoxLayout(b6, BoxLayout.LINE_AXIS));
b6.add(initialState);
b7.setLayout(new BoxLayout(b7, BoxLayout.LINE_AXIS));
b7.add(tableShow);
b7.add(input);
b7.setVisible(false);
this.setEventSimpleRadio();
this.setEventSecondRadio();
secondBGRadio.setVisible(false);
mainBGRadio.setLayout(new BoxLayout(mainBGRadio, BoxLayout.LINE_AXIS));
secondBGRadio.setLayout(new BoxLayout(secondBGRadio, BoxLayout.LINE_AXIS));
container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));
main.setLayout(new GridLayout(2, 1));
b1.setBackground(Color.ORANGE);
b2.setBackground(Color.ORANGE);
b3.setBackground(Color.ORANGE);
b4.setBackground(Color.ORANGE);
b5.setBackground(Color.ORANGE);
b6.setBackground(Color.ORANGE);
b7.setBackground(Color.ORANGE);
mainBGRadio.setBackground(Color.ORANGE);
secondBGRadio.setBackground(Color.ORANGE);
container.add(b1);
container.add(b2);
container.add(mainBGRadio);
container.add(secondBGRadio);
container.add(b7);
container.add(b6);
container.add(b4);
container.add(b5);
container.add(b3);
outPutField.add(output);
outPutField.add(scrool);
outPutField.setLayout(new GridLayout(0,1, 5, 5));
container.setBackground(Color.ORANGE);
main.add(container);
main.add(outPutField);
this.setContentPane(main);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
//文本区域
公共静态JTextArea输出=新的JTextArea(“=======================================================================================================”);
//杰布顿
private JButton bouton=new JButton();
私有JButton tpBouton=新JButton(“tp205”);
//杰拉贝尔
专用JLabel标签=新JLabel(“TP DE 205”);
公共静态JLabel初始状态=新JLabel(“测试”);
公共静态JLabel状态=新JLabel(“”);
公共静态JLabel tableShow=新JLabel(“enter l'element a rechercher:”);
公共静态JLabel finalState=新JLabel(“”);
private JLabel explicitText=new JLabel();
//JTextField
私有JFormattedTextField输入=新的JFormattedTextField(NumberFormat.getIntegerInstance());
//JTextField输入=新的JTextField(“Choisir l'element a rechercher…”);
//杰帕内尔
JPanel mainBGRadio=新的JPanel();
JPanel secondBGRadio=newjpanel();
JPanel b7=新的JPanel();
JPanel main=新的JPanel();
JPanel容器=新的JPanel();
JPanel outPutField=新的JPanel();
//合奏
私有合奏集=新合奏();
//杰拉迪布顿
//主要群体
私有JRadioButton查找=新JRadioButton(“查找”);
私有JRadioButton insert=新JRadioButton(“insert”);
私有JRadioButton delete=新JRadioButton(“delete”);
私有JRadioButton差异=新JRadioButton(“差异”);
专用JRadioButton交叉口=新JRadioButton(“交叉口”);
私有JRadioButton union=新JRadioButton(“union”);
//第二组
私有JRadioButton sortedList=新JRadioButton(“liste Trie”);
私有JRadioButton simpleList=newjradiobutton(“liste Simple”);
私有JRadioButton doubleList=新JRadioButton(“liste Avec Doublons”);
私有JRadioButton simpleVector=新JRadioButton(“向量简单”);
私有JRadioButton sortedVector=新的JRadioButton(“vectuer Trie”);
私有JRadioButton booleanVector=新JRadioButton(“向量布尔”);
//JButtonGroup
//某bouton群
private ButtonGroup mainBG=new ButtonGroup();
private ButtonGroup secondBG=new ButtonGroup();
//ArrayList
private ArrayList radioList=新建ArrayList(){{
添加(查找);
添加(插入);
增加(删除);
添加(联合);
添加(交叉点);
加(差);
}};
专用ArrayList radioFunctionList=新ArrayList(){{
添加(分类列表);
增加(双重名单);
添加(简单列表);
添加(simpleVector);
添加(分拣机);
加法(布尔向量);
}};
//字体
Font=新字体(“ubuntu”,Font.BOLD,45);
Font explicitFont=新字体(“ubuntu”,Font.BOLD,15);
Font stateFont=新字体(“ubuntu”,Font.BOLD,25);
字体文本区域字体=新字体(“ubuntu”,Font.ITALIC,19);
公共场所(){
}
/**
*这是包含所有contains元素的主窗口
*/
蒙特勒公共图书馆(){
//窗口参数
本集标题(“TP 205”);
这个。设置大小(800800);
此.setLocationRelativeTo(空);
//波顿构型
bouton.setText(“模拟物”);
addActionListener(新的BtnClass());
addActionListener(新的BtnClass());
tpBouton.挫折背景(颜色:黑色);
tpBouton.setFont(显式字体);
tpBouton.setForeground(颜色:白色);
//JLabel配置
explicitText.setText(“Bienvenur sur notre tp de 205”);
label.setFont(字体);
explicitText.setFont(explicitFont);
explicitText.setForeground(颜色:白色);
标签。设置前景(颜色。白色);
状态。设置前景(颜色。白色);
state.setFont(stateFont);
initialState.setForeground(颜色:白色);
setFont(stateFont);
最后状态。设置前景(颜色。白色);
finalState.setFont(stateFont);
//输入配置
input.setFont(显式字体);
输入.setPreferredSize(新维度(150,30));
输入.设置前景(颜色.黑色);
input.setMaximumSize(新维度(Integer.MAX_值,input.getMinimumSize().height));
output.setFont(textareaFont);
output.setWrapStyleWord(true);
output.setLineWrap(true);
JScrollPane scrool=新的JScrollPane();
scrool.setboorder(BorderFactory.createTitledBorder(“LIONEL”));
scrool.setViewportView(输出);
//布局配置
JPanel b1=新的JPanel();
b1.设置布局(新的BoxLayout(b1,BoxLayout.LINE_轴));
b1.添加(标签);
JPanel b2=新的JPanel();
b2.setLayout(新的BoxLayout(b2,BoxLayout.LINE_轴));
b2.添加(明确文本);
JPanel b3=新的JPanel();
b3.setLayout(新的BoxLayout(b3,BoxLayout.LINE_轴));
b3.添加(tpBouton);
b3.添加(bouton);
JPanel b4=新的JPanel();
b4.设置布局(新的BoxLayout(b4,BoxLayout.LINE_轴));
b4.添加(州);
JPanel b5=新的JPanel();
b5.设置布局(新的BoxLayout(b5,BoxLayout.LINE_轴));
b5.添加(最终状态);
JPanel b6=新的JPanel();
b6.设置布局(新的BoxLayout(b6,BoxLayout.LINE_轴));
b6.添加(初始状态);
b7.设置布局(新的BoxLayout(b7,BoxLayout.LINE_轴));
b7.添加(表显示);
b7.添加(输入);
b7.设置可见(假);
this.setEventSimpleRadio();
此.setEventSecondRadio();
secondBGRadio.setVisible(假);
mainBGRadio.setLayout(新的BoxLayout(mainBGRadio,BoxLayout.LINE_轴));
secondBGRadio.setLayout(新的BoxLayout(secondBGRadio,BoxLayout.LINE_轴));
container.setLayout(新的BoxLayout(container,BoxLayout.PAGE_轴));
main.setLayout(新网格布局(2,1));
b1.立根背景(颜色:橙色);
b2.背景(颜色为橙色);
b3.挫折背景(颜色:橙色);
//public static JTextArea output = new JTextArea("==== The Outputs HERE =====;
public static JTextArea output = new JTextArea(5, 30);
output = "========= The Outputs HERE ================================");