13

JPanelにJTextAreaがあります。JTextAreaでJPanel全体を埋め、JPanelのサイズが変更されたときにサイズを変更し、入力するテキストが多すぎる場合にスクロールするにはどうすればよいですか?

4

2 に答える 2

21
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());  //give your JPanel a BorderLayout

JTextArea text = new JTextArea(); 
JScrollPane scroll = new JScrollPane(text); //place the JTextArea in a scroll pane
panel.add(scroll, BorderLayout.CENTER); //add the JScrollPane to the panel
// CENTER will use up all available space

詳細については、http //download.oracle.com/javase/6/docs/api/javax/swing/JScrollPane.htmlまたはhttp://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.htmlを参照してください。 JScrollPaneの詳細

于 2010-10-01T22:50:45.213 に答える
7

JTextAreaをJScrollPane内に配置し、サイズを固定するレイアウトでJPanelに配置します。たとえば、GridBagLayoutの例は、次のようになります。

JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());

JScrollPane scrollpane = new JScrollPane();
GridBagConstraints cons = new GridBagContraints();
cons.weightx = 1.0;
cons.weighty = 1.0;
panel.add(scrollPane, cons);

JTextArea textArea = new JTextArea();
scrollPane.add(textArea);

これは大まかなスケッチにすぎませんが、その方法を説明する必要があります。

于 2010-10-01T22:50:54.207 に答える