[英]I'm having issues with aligning elements (Java GUI / Swing);
I'm attempting to align TextField vertically next to some labels, however the alignment isn't working for the TextField in which it does the Labels 我正在尝试将TextField垂直对齐到某些标签旁边,但是对齐不适用于TextField,它在其中执行标签
At first I thought it was size miscalculations however that's not the case, I've tried aligning left and right panels to their according sides (EAST and WEST) however that didn't work either. 起初我认为这是大小误算,但事实并非如此,我已经尝试将左右面板对齐到他们的相应侧面(EAST和WEST),但是这也没有用。
JPanel leftPanel = new JPanel();
leftPanel.setBounds(0,0, 100, 300 );
JPanel rightPanel = new JPanel();
rightPanel.setBounds(100, 0, 50, 300);
JLabel fiftyNoteLabel = new JLabel("TOTAL $50s");
JLabel twentyNoteLabel = new JLabel("TOTAL $20s");
JTextField fiftyNoteText = new JTextField("0");
JTextField twentyNoteText = new JTextField("0");
main.add( leftPanel );
main.add( rightPanel );
leftPanel.add( fiftyNoteLabel, BorderLayout.NORTH );
leftPanel.add( twentyNoteLabel, BorderLayout.NORTH );
rightPanel.add( fiftyNoteText, BorderLayout.NORTH );
rightPanel.add( twentyNoteText, BorderLayout.NORTH );
main.setVisible( true );
leftPanel.setVisible( true );
rightPanel.setVisible( true );
Ooops, turns out Java handles components being added sequentially, I was attempting to alter the position by changing the alignment of the element. Ooops,结果是Java处理顺序添加的组件,我试图通过改变元素的对齐来改变位置。 However I was supposed to be adding the elements in order.
但是我应该按顺序添加元素。
EG. 例如。 LABEL -> TEXTFIELD = "Hello" [ ]
LABEL - > TEXTFIELD =“你好”[]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.