여기서 중요한 비트가 기본 크기입니다. 귀하의 다른 질문에, 당신은 다음 코드를 사용하여 작동하도록했다고하셨습니다. 이 것
locationPanel.setLayout(new MigLayout("gap rel 2", "[0:0, grow 60, center][grow 40, left]"));
usagePanel.setLayout(new MigLayout("gap rel 2", "[0:0, grow 60, center][grow 40, left]"));
structuralAspectsPanel.setLayout(new MigLayout("gap rel 2", "[0:0, grow 60, center][grow 40, left]"));
또한
locationPanel.setLayout(new MigLayout("gap rel 2", "[:0:, grow, center][grow, left]"));
usagePanel.setLayout(new MigLayout("gap rel 2", "[:0:, grow, center][grow, left]"));
structuralAspectsPanel.setLayout(new MigLayout("gap rel 2", "[:0:, grow, center][grow, left]"));
//Obviously you could use any number not just 0
옵션을 사용할 수를 쓴 한 경우 일 수 있습니다 (여기서 X < = Y < = Z)
X:Y:Z
X:Y:
:Y:Z
:Y:
:Y
가 왜 그것을 않습니다 이 작업을 수행?
열이 같은 비율로 증가하고 세 개의 패널 모두에서 첫 번째 열의 기본 크기를 설정할 때 MigLayout
은 초기 열 크기를 기본 크기로 설정하므로 초기 크기를 설정합니다.
essensce에서는 같은 크기의 열을 설정하고 같은 비율로 커지므로 같은 크기로 유지됩니다. 따라서 그들은 줄을 서 있습니다. 당신이 MigLayout이 UI에 시각적 레이아웃 정보를 렌더링하는 디버그 모드를 가지고 있다는 사실을 알고 계셨습니까 Y
이
import java.awt.*;
import javax.swing.*;
import net.miginfocom.swing.MigLayout;
public class MigLay extends JFrame {
private MigLay() {
super("Button Layout");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new MigLayout("wrap", //Layout Constraints
"grow, fill", //Column Constraints
"grow, fill")); //Row Constraints
createPanels();
pack();
setMinimumSize(getSize()); //Sets minimum size to the preferred size. Remove or change this line if you do not want that to happen
setVisible(true);
}
private void createPanels() {
JPanel locationPanel = new JPanel();
JPanel usagePanel = new JPanel();
JPanel structuralAspectsPanel = new JPanel();
//JLabels for font metrics
JLabel one = new JLabel("This is the first of all labels");
JLabel two = new JLabel("Second Label");
JLabel three = new JLabel("This Label is fairly large and long and pushes the text around");
JLabel four = new JLabel("A label in the usage panel");
JLabel five = new JLabel("And another one and another one and another one");
//Font Metrics
FontMetrics metrics = three.getFontMetrics(three.getFont()); //Take longest label manually or dynamically (You will have to add that code)
int width = metrics.stringWidth(three.getText());
locationPanel.setLayout(new MigLayout("gap rel 2", "[:" + width + ", grow, center][grow, left]"));
locationPanel.setBorder(BorderFactory.createTitledBorder("Location"));
usagePanel.setLayout(new MigLayout("gap rel 2", "[:" + width + ", grow, center][grow, left]"));
usagePanel.setBorder(BorderFactory.createTitledBorder("Usage"));
locationPanel.add(one);
locationPanel.add(new JCheckBox("Checkbox with Label"), "wrap");
locationPanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
locationPanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
locationPanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
locationPanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
locationPanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
locationPanel.add(new JSeparator(), "growx, span");
locationPanel.add(two);
locationPanel.add(new JCheckBox("Checkbox with Label"), "wrap");
locationPanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
locationPanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
locationPanel.add(new JSeparator(), "growx, span");
locationPanel.add(three);
locationPanel.add(new JCheckBox("Checkbox with Label"), "wrap");
locationPanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
locationPanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
usagePanel.add(four);
usagePanel.add(new JCheckBox("Checkbox with Label"), "wrap");
usagePanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
usagePanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
usagePanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
usagePanel.add(new JSeparator(), "growx, span");
usagePanel.add(five);
usagePanel.add(new JCheckBox("Checkbox with Label"), "wrap");
usagePanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
usagePanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
usagePanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
usagePanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
usagePanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
usagePanel.add(new JCheckBox("Checkbox with Label"), "skip, wrap");
getContentPane().add(locationPanel);
getContentPane().add(usagePanel);
}
public static void main(String[] args) {
new MigLay();
}
}
Font Metrics
에 의해 결정된다작업 예
는
:Y
를 사용? 어떤 경우에는 무슨 일이 벌어지고 있는지 알아내는 데 도움이 될 것입니다. 즉, '0 : 0'은 최소값이고 기본 크기는 0이므로 구성 요소가 기본적으로 보이지 않을 때까지 축소 할 수 있다고 가정합니다. 그러나 실제 크기는 레이아웃을 정의한 방법에 따라 그보다 더 클 것입니다.시도하고 도움을 청하려면 더 많은 정보가 필요합니다. – Thomas필자는 패널을''debug "'- 옵션으로 테스트했지만 차이점이 없으므로 생략했습니다. 각각의'JLabel'은 자체 적색 테두리를 가지고 있습니다. '0 : 0'을 사용하지 않으면 왼쪽이 조금 더 커지고, 왼쪽면은 조금 작아집니다. 여분의 세포가 없기 때문에 어떤 정보를 얻을 수 있는지 알지 못합니다. 또한 "0"매개 변수가 설명되지 않았기 때문에 내 질문에 MigLayout 설명서가 더 많이 중점을 둡니다. – hamena314
'... he 매개 변수 "0"이 설명되지 않았습니다. - 음, 0이 실제로 추론 할 수있는 것 외에도 특별한 의미가 아니라면 특별히 문서에 언급하지 않았습니다. – Thomas