MigLayout을 사용하여 부모 요소의 높이를 높이기 위해 표현식을 사용하려고합니다. "height 100 %"그러나 MigLayout에는 일종의 피드백 루프가있어 높이가로드 될 때 최대 값으로 이동합니다. 이 문제는 MiGPanel이 JScrollPane에 포함될 때만 발생합니다. JScrollPane을 처리하는 코드 행을 제거하고 MiGPanel을 JFrame에 추가하면 프로그램이 의도 한대로 실행됩니다. 이 과자를보기 위해 부울 문을 추가했습니다.Java에서 MigLayout을 사용하여 높이 또는 너비가 100 %로 설정된 경우 하위가 부모의 경계를 벗어나 확장됩니다.
참고 : 이 수정 프로그램을 보았지만 프로그램 하단에 여백이없는 솔루션을 사용하고 싶습니다. 여기 How to prevent MigLayout from exceeding a container's bounds
코드입니다 :
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import net.miginfocom.swing.MigLayout;
public class StackOverFlowQuestion {
public static void main(String[] args) {
JPanel MiGPanel = new JPanel();
MiGPanel.setBackground(Color.red);
MiGPanel.setLayout(new MigLayout());
JPanel greenPanel = new JPanel();
greenPanel.setBackground(Color.green);
MiGPanel.add(greenPanel, "pos 0 0, width 33%, height 100%");
JPanel yellowPanel = new JPanel();
yellowPanel.setBackground(Color.yellow);
MiGPanel.add(yellowPanel, "pos 33% 0, width 33%, height 100%");
JPanel bluePanel = new JPanel();
bluePanel.setBackground(Color.blue);
MiGPanel.add(bluePanel, "pos 66% 0, width 34%, height 100%");
JFrame mainFrame = new JFrame();
mainFrame.setLayout(new BorderLayout());
boolean scroll = true;
if(scroll){
JScrollPane scrollPane = new JScrollPane();
scrollPane.add(MiGPanel);
scrollPane.setViewportView(MiGPanel);
mainFrame.add(scrollPane);
}else{
mainFrame.add(MiGPanel);
}
mainFrame.add(scrollPane);
mainFrame.pack();
mainFrame.setSize(900, 600);
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
}
}
이 문제가있는 유일한 사람이 될 수 있습니까? –