I have to write a very simple code (GUI code) and my last buttons are supposed to be in the middle at the bottom of the frame. Well, they are not in the middle. They are at the bottom but on the left side of the frame.
/* I called my JFrame win; :)
* The JPanel Jp1;
* I used this: win.add(Jp1, BorderLayout.CENTER);
* What did I do wrong? I don't want to post the whole code cause everything is working;
* well except this;
*/
FireBlah
0
Newbie Poster
Recommended Answers
Jump to PostYou'll want to add the the JButton to a JPanel, and add the JPanel to the JFrame.
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JButton button = new JButton("My Button");panel.add(button);
frame.setLayout(new BorderLayout()); // might not need this, test it.
frame.add(panel, BorderLayout.CENTER);
Jump to PostIm getting the same problem, my two JButtons dont appear where I want them too. I think it something to do with the Layout but I am not sure. I aint using a layout manager but when I do it shows buttons in the top centre :(
All 6 Replies
ztini
FireBlah
0
Newbie Poster
StevoLord
0
Newbie Poster
FireBlah
0
Newbie Poster
Katana24
3
Junior Poster
Katana24
3
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.