gpt4 book ai didi

java - GUI Box layout Y AXIS not inline

转载 作者:行者123 更新时间:2023-11-30 07:53:29 24 4
gpt4 key购买 nike

GUI

我正在设计这个 GUI,整个框架使用 BorderLayout,然后有 3 个面板,boggle Board 面板使用 GridLayout,Enter Words Found 面板(由 JTextArea、Time left JLabel 和 Shake Dice JButton 组成)正在使用带 Y 轴的 BoxLayout,当前 Word 面板(由当前 Word JLabel、提交 Word JButton 和评分 JLabel 组成)正在使用 FlowLayout。

如您所见,JTextArea 并未沿 Y 轴与 Time Left JLabel 和 Shake Dice JButton 内联,我不知道为什么会这样。如果有人能阐明他们为什么不排队,那就太好了,谢谢。

这是我的 Enter Words Found JPanel 代码:

// Adding words found JPanel
wordFoundPanel = new JPanel();
wordFoundPanel.setLayout(new BoxLayout(wordFoundPanel, BoxLayout.Y_AXIS));
wordFoundPanel.setBorder(new TitledBorder("Enter Words Found"));

wordArea = new JTextArea();
wordArea.setLineWrap(true);
wordArea.setWrapStyleWord(rootPaneCheckingEnabled);

// Adding JScrollPane to the wordArea
scroll = new JScrollPane(wordArea);
scroll.setMinimumSize(new Dimension(200, 180));
scroll.setPreferredSize(new Dimension(200, 180));
scroll.setMaximumSize(new Dimension(200, 180));
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

wordFoundPanel.add(scroll);

// Adding Clock Label
clockLabel = new JLabel("3:00", CENTER);
clockLabel.setMinimumSize(new Dimension(200, 100));
clockLabel.setPreferredSize(new Dimension(200, 100));
clockLabel.setMaximumSize(new Dimension(200, 100));
clockLabel.setFont(new Font("Tahoma", Font.BOLD, 30));
clockLabel.setBorder(new TitledBorder("Time Left"));

wordFoundPanel.add(clockLabel);

// Adding Shake Dice button
shakeDiceButton = new JButton("Shake Dice");
shakeDiceButton.setMinimumSize(new Dimension(200, 100));
shakeDiceButton.setPreferredSize(new Dimension(200, 100));
shakeDiceButton.setMaximumSize(new Dimension(200, 100));

wordFoundPanel.add(shakeDiceButton);

frame.add(wordFoundPanel, BorderLayout.EAST);

最佳答案

How to Use BoxLayout修复对齐问题部分,我们可以读到:

In general, all the components controlled by a top-to-bottom BoxLayout object should have the same X alignment

所以只需在您的三个组件上调用例如 setAlignmentX(Component.RIGHT_ALIGNMENT);,它就会修复这个奇怪的显示。

enter image description here

关于java - GUI Box layout Y AXIS not inline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44717234/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com