2
다음 예제에서는 창을 최대화하거나 최소화 할 때 텍스트 영역을 확장 할 수 있기를 원합니다. 현재 텍스트 영역은 cols/rows로 설정됩니다. 최대화를 클릭하면 창이 펼쳐질 때 텍스트 영역이 확장되어야합니다.Java swing and expand window/textarea
참고 : 이것은 일종의 의사적인 예입니다. GridBagLayout 관리자를 사용하는 이유는 더 많은 구성 요소를 추가 할 수 있습니다.
는아래의 버전은 내가 원하는 걸 제공 :
package org.berlin.pino.test.functional.jogl;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class BasicText {
public static JPanel buildPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final GridBagConstraints gc = new GridBagConstraints();
final JTextArea text = new JTextArea("Text");
final JScrollPane scrollPane = new JScrollPane(text);
gc.fill = GridBagConstraints.BOTH;
gc.weightx = 1;
gc.weighty = 1;
// Add the textarea -> scroll pane -> to the panel -> to the jframe
panel.add(scrollPane, gc);
return panel;
}
public static void main(String[] args) {
JFrame frame = new JFrame("Hello World!");
frame.setLayout(new GridBagLayout());
final GridBagConstraints gc = new GridBagConstraints();
gc.fill = GridBagConstraints.BOTH;
gc.weightx = 1;
gc.weighty = 1;
frame.add(buildPanel(), gc);
frame.setPreferredSize(new Dimension(300, 300));
frame.setLocation(200, 100);
frame.setBackground(Color.white);
frame.pack();
frame.setVisible(true);
}
} // End of the class //
감사합니다. –