对我的JLabel
组件的定位存在小问题。JLabel/JPanel定位问题。 (GridBagLayout)
代码:
public class delete {
public static void main(String[] args){
GridBagConstraints gbc = new GridBagConstraints();
//Adding the JPanels. Panel for instructions
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
//JLabel for the Instructions.
JLabel label = new JLabel("<html> Instructions: Type in the grades you’ve received, along with the weights they’ll have in the determination of your overall average. <br> After you press ‘Calculate’, the results will show your average so far. <br> Every grade you enter must be a non-negative number, and every percentage/weight you enter must be a positive number :)</html>");
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.PAGE_START;
gbc.weighty = 1;
panel.add(label, gbc);
//JLabel1 for Assingment/Grade/Weight(Percent)
JLabel label1 = new JLabel("<html><pre>Assingment\t\t\t\t\tWeight\t\t\t\t\tPercentage</pre></html>");
gbc.gridx = 0;
gbc.gridy = 0;
panel.add(label1, gbc);
//New frame set
JFrame frame = new JFrame("Grade Calculator");
frame.setVisible(true);
frame.setSize(750,500);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.add(panel);
}
}
现在现在这个位置JLabel
(label
)在这是我想要的框架的顶部。问题是JLabel
(label1
)我想label1
略低于标签。
如果我设置gbc.gridy = 0
,label1
显示在标签的顶部使两个单独的碰撞在一起。
当我设置gbc.gridy = 1
时,label1
一直走到框架的底部。
现在我想要label1
只是略低于标签,但我不能使用漂浮与gridy
。我怎样才能解决这个问题?
谢谢这非常重要。我一直在问这里一个问题之前总是使用Java教程,但直到有人在这里解释之后,我才能完全理解它。再次感谢。 – bob9123
你好,还有一件事我遇到了问题。你能帮我解答吗? – bob9123
@ bob9123我通常会提供指向其他教程,文档或支持文档的链接,因为您不应该把我的话当做事情;)。如果你有更多的问题,也许考虑问另一个问题,只需提供一个链接回到这个作为参考点的人谁可能还没有读过这个;) – MadProgrammer