0

私はまだJavaについて学んでいて、簡単なコードを持っています

import javax.swing.*;

Public class Test extends JFrame{
JLabel name = new JLabel("Name");
JTextArea ta = new JTextArea();

Test(){
    this.setSize(435, 400);
    this.setTitle("Test");
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setLayout(null);
    name.setBounds(10, 10, 50, 20);
    this.add(name);
    ta.setBounds(90, 10, 300, 200); 
    ta.setLineWrap(true);
    JScrollPane scroll = new JScrollPane(ta);
    this.add(scroll);
}

public static void main(String [] args){
    new Test().setVisible(true);
}
}

どのレイアウトを選択すればよいですか? 名前ラベルの横にテキストエリアを表示したい

4

1 に答える 1

0

Label と TextArea だけの場合は、単純なGridLayout

Test(){

    setLayout(new GridLayout(1, 2));   // sets a Grid Layout with 1 row and 2 columns
    add(name);

    JScrollPane scroll = new JScrollPane(ta);
    ta.setLineWrap(true);
    add(scroll);


}

public static void main(String[] args) {
    JFrame frame = new Test();
    frame.setSize(435, 400);
    frame.setTitle("Test");
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    frame.setVisible(true);
}
于 2013-10-20T14:24:06.340 に答える