I have this code:
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
panel.add(label, BorderLayout.LINE_START);
panel.add(label2, BorderLayout.LINE_START);
panel.add(textfield, BorderLayout.LINE_END);
panel.add(textfield2, BorderLayout.LINE_END);
panel.add(button5);
panel.revalidate();
panel.repaint();
label.setText("Geef de basis van de driehoek in cm: ");
label2.setText("Geef de hoogte van de driehoek in cm: ");
}
});
Which corresponds with this screenshot:
I want it to actually look like this:
I'm new to Java and I know this is probably a dumb question, but I can't figure it out with information on the Internet.
Thanks in advance!
Looking at the code you provided then I see that the top three buttons are not added in this method so I suppose that they are already there:
In that case lets break your GUI down into bits, like so:
We can now make those three left over rechtangles. These rectangles are going to be
JPanels
each having the corresponding components in them:So:
And that should solve your problem, if you have any questions regarding the answer please let me know.
I hope this helps :)
EDIT #1:
Code version 2: