I used a borderLayout, added a JLabel in north then added a jpanel into the center with a grid layout (8,1) and then added two empty panels to make the extra spaces on the far left and right. So my question, is there another way to make these spaces? Frame I want
Frame I made
SOURCE: make spaces in this JFrame
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
use the following code
public class Testing1 extends javax.swing.JFrame { public Testing1() {
JFrame frame = new JFrame();
JPanel panel = createPanel();
panel.setLocation(100, 100);
//panel.setLayout(null);
this.add(panel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
initComponents();
}
private JPanel createPanel() {
jPanel1 = new JPanel(new GridLayout(0, 1, 10, 5));
EmptyBorder panelBorder = new EmptyBorder(10, 10, 10, 10); jPanel1.setBorder(panelBorder); EmptyBorder border = new EmptyBorder(5, 20, 5, 20); LineBorder line = new LineBorder(Color.blue, 2, true); CompoundBorder compound = new CompoundBorder(line, border); for (int i = 0; i <12; i++) { JLabel label = new JLabel(“Label” + i); label.setBorder(compound); // label.setBounds(13, 100, 100, 50); jPanel1.add(label); } return jPanel1; } SOURCE: JFRAME
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.