Frage

Ich habe eine jtextarea in einem jpanel. Wie kann ich die JTextArea das gesamte JPanel füllen und die Größe der Größe, wenn die JPanel -Größe und Scrollen, wenn zu viel Text eingegeben wird?

War es hilfreich?

Lösung

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

Sehen http://download.oracle.com/javase/6/docs/api/javax/swing/jscrollpane.html oder http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html Weitere Informationen zu JScrollPane

Andere Tipps

Legen Sie die jTextarea in eine jScrollpane und legen Sie das mit einem Layout, das die Größe festlegt, mit einem Layout. Ein Beispiel mit einem Gridbaglayout könnte beispielsweise so aussehen:

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);

Dies ist nur eine grobe Skizze, aber sie sollte veranschaulichen, wie es geht.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top