Java – how to set the distance between vertically sorted elements?
•
Java
I have this Code:
JPanel myPanel = new JPanel(); myPanel.setLayout(new @R_778_2419@Layout(myPanel,@R_778_2419@Layout.Y_AXIS)); JButton button = new JButton("My Button"); JLabel label = new JLabel("My label!!!!!!!!!!!"); myPanel.add(button); myPanel.add(label);
In this way, there is no distance between the elements I get I mean, the top element always touches the bottom element How can I change it? I want some separation between my elements?
I want to add some "middle" jpanels (with some sizes) between my elements But I don't think it's an elegant way to achieve the desired results Can someone help me?
Solution
JPanel myPanel = new JPanel();
JPanel myPanel = new JPanel(); myPanel.setLayout(new @R_778_2419@Layout(myPanel,@R_778_2419@Layout.Y_AXIS)); JButton button = new JButton("My Button"); JLabel label = new JLabel("My label!!!!!!!!!!!"); myPanel.add(button); myPanel.add(@R_778_2419@.createVerticalStrut(20)); myPanel.add(label);
Will be a way
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码