如何将JPanel
的黄色JLabel
向右移动/对齐,并将其他JLabel
向左移动/对齐?
You use an appropriate layout manager.
One option is to use a panel with a horizontal BoxLayout
:
Box panel = Box.createHorizontalBox();
panel.add( leftLabel );
panel.add( Box.createHorizontalGlue() );
panel.add( yellowLabel );
Another option is to use a panel with a BorderLayout
:
JPanel panel = new JPanel( new BorderLayout() );
panel.add(leftLabel, BorderLayout.LINE_START);
panel.add(yellowLabel, BorderLayout.LINE_END);
Read the section from the Swing tutorial on Layout Mangers for more information and working examples.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.