lecardo
lecardo

Reputation: 1212

JDialog layout issues

I'm using a JDialog to create a customized dialog box for my Java project. I'm having issues with the layout at the moment. It seems each JLabel I add to the dialog goes over the existing one. Do I need to add some sort of JPanel?

I also seem to have a issue with the size. I set it too 500x500 but why does it only goes as large as the text width?

JDialog processData = new JDialog(f1, "TItle goes here");
JLabel centretext = new JLabel("Look at me im centre!");
JLabel leftext = new JLabel("LOok at me im left");
JLabel righttext = new JLabel("LOok at me im right");
processData.setVisible(true);
processData.add(centretext);
processData.add(lefttext);
processData.add(rightext);
processData.toFront();
processData.setSize(500,500);
processData.setLocation(500,500);
processData.pack();

Upvotes: 0

Views: 239

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347204

JDialog uses a BorderLayout by default, which means, it will only show a single component in any of the five available positions, all the others get ignored.

Consider using a different layout manager. See Laying Out Components Within a Container for more details

Upvotes: 2

Related Questions