Java jtextareaは、自動化してスクロールします
-
27-09-2019 - |
質問
私はjpanelにjtextareaを持っています。 jtextareaにJPanel全体を埋めて、JPANELがサイズを変更し、テキストが入力されているときにスクロールしたときにサイズを変更するにはどうすればよいですか?
解決
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の詳細については
他のヒント
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);
これは大まかなスケッチにすぎませんが、それを行う方法を説明する必要があります。
所属していません StackOverflow