GridBagLayout (2 행, 행 0에 2 구성 요소, 행 1에 1 구성 요소)을 사용하여 간단한 테스트 코드를 참조하십시오. weighty
을 첫 번째 행의 경우 0.01, 두 번째 행의 경우 1로 지정했지만 화면의 비율은 0.3 대 0.7에 가깝습니다. 첫 번째 행의 높이가 전체 텍스트 영역이 들어갈 수 있도록 크기가 조정 된 것 같습니다.GridBagLayout & JScrollPane : 행 높이를 줄이는 방법은 무엇입니까?
첫 번째 행의 높이를 줄여서 JScrollPane의 스크롤 막대가 나타나게하려면 어떻게해야합니까?
public class Test {
public static void main(String... args) {
String text = "text\n\n\n\n\n\n\n\ntext";
JFrame frame = new JFrame();
JTextArea area;
JScrollPane pane;
JPanel desktop = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.25;
c.weighty = 0.05;
area = new JTextArea(text);
area.setBackground(Color.RED);
pane = new JScrollPane(area);
desktop.add(pane, c);
c.gridx = 1;
c.gridy = 0;
c.weightx = 0.75;
c.weighty = 0.05;
area = new JTextArea(text);
area.setBackground(Color.BLUE);
pane = new JScrollPane(area);
desktop.add(pane, c);
c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.gridy = 1;
c.weightx = 0;
c.weighty = 1;
c.gridwidth = 2;
area = new JTextArea(text);
area.setBackground(Color.GREEN);
pane = new JScrollPane(area);
desktop.add(pane, c);
frame.setContentPane(desktop);
frame.setPreferredSize(new Dimension(800, 600));
frame.pack();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
}
이것이 맞습니다 +1, – mKorbel
그 트릭을 않습니다 - 감사합니다. – assylias