Results 1 to 2 of 2
- 03-18-2012, 10:24 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 1
- Rep Power
- 0
How to change the location of buttons on a JFrame???
Hi!,
By executing the below code,Im getting the 4 buttons(side by side) in the top-center position.
But,I want to change the positions of the button to the complete left side of my frame...i,e; one below the other...How to change it...Pls help me out...Thanks ...:)
public Systems()
{
JFrame frame = new JFrame("FIRST OUTLAY ");
JPanel pan = new JPanel();
button1 = new JButton("OS info");
button2 = new JButton("N/W info");
button3 = new JButton("Java info");
button4 = new JButton("Memory info");
area = new JTextArea();
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
pan.add(button1);
pan.add(button2);
pan.add(button3);
pan.add(button4);
//pan.setLayout(new FlowLayout());
jsp= new JScrollPane(area);
frame.add(jsp);
jsp.setBounds(100, 60, 380, 400);
frame.add(pan);
frame.setSize(600, 600);
frame.setLocation(100,100);
frame.setVisible(true);
}
- 03-18-2012, 11:57 AM #2
Re: How to change the location of buttons on a JFrame???
Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
1) Look around the FAQs section of the site and learn how to post code so it retains its formatting.
2) Don't use setBounds(...), use an appropriate layout manager. In your code sample, setBounds(...) wouldn't be effective, and you wouldn't see the scroll pane either.
3) As far as your immediate question is concerned, FlowLayout has more than one constructor. Apply the one most appropriate to your need.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
jSplitPane and divider Location after jFrame resize?
By michalss in forum AWT / SwingReplies: 6Last Post: 04-21-2011, 12:33 PM -
JFrame-buttons missing
By Jodokus in forum AWT / SwingReplies: 5Last Post: 01-20-2011, 05:10 PM -
Selecting Radio Buttons to change frames?
By jchsu in forum AWT / SwingReplies: 3Last Post: 02-25-2010, 11:06 AM -
JFrame 's components size and location problem
By petrosgraf in forum Threads and SynchronizationReplies: 5Last Post: 04-18-2009, 02:24 AM -
How to Change MySQL Database Location
By sayan751 in forum JDBCReplies: 3Last Post: 03-19-2009, 02:42 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks