Results 1 to 3 of 3
Thread: Swing layouts
- 07-07-2011, 11:34 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 35
- Rep Power
- 0
Swing layouts
Hey yall,
Been trying to understand layouts for a while now,started with GridbagLayout and the only way I could get what I want is through sheer luck.
Now Im making a gui for a chat application Im working on and using BorderLayout to place components onto a frame and I can't seem to get what I want.
Can someone help me out please.
this is the panel Im adding onto the frame
this is the frame Im adding the panel ontoJava Code:public void createConfig(){ configPanel = new JPanel(); portNumber = new JTextField(5); friend = new JTextField(5); ipAddresText = new JTextField(5); connect = new JButton("Connect"); JLabel portNumberLabel = new JLabel("Enter port number"); JLabel friendLabel = new JLabel("Enter name"); JLabel ipAddress = new JLabel("Enter ip address"); JLabel onlineFriends = new JLabel("Friends"); configPanel.setLayout(new BoxLayout(configPanel, BoxLayout.Y_AXIS)); configPanel.setSize(500,500); configPanel.setBackground(Color.LIGHT_GRAY); //configPanel.add(portNumberLabel); //configPanel.add(portNumber); //configPanel.add(friendLabel); //configPanel.add(friend); //configPanel.add(ipAddress); //configPanel.add(ipAddresText); Dimension dimension = new Dimension(50,50); friendsList.setPreferredSize(dimension); configPanel.add(onlineFriends); configPanel.add(friendsList); }
The client constructor creates an ok chat window but its the panel (createConfig()) that Im worried about.Java Code:public void addToFrame() { createConfig(); Container guiFrame = this.getContentPane(); guiFrame.setLayout(new BorderLayout()); guiFrame.add("Center", new Client(loginame)); guiFrame.add("North", new JLabel("welcome "+loginame)); guiFrame.add("East",configPanel); this.setSize(300,300); this.setVisible(true); }
Thanx in advance...
- 07-07-2011, 12:32 PM #2
Have you gone through the tutorial?
Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
Also
-- a contentPane has a default BorderLayout.
-- the add(...) overload you're using is obsolete as of version 1.1. Get with the times!
Container (Java Platform SE 6)
-- Don't use setSize(...) and avoid using setPreferredSize(...) in client code. Let the layout managers do their job.
db
- 07-08-2011, 11:10 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 35
- Rep Power
- 0
Similar Threads
-
Layouts and Sizes
By Bagzli in forum New To JavaReplies: 2Last Post: 07-01-2011, 05:24 PM -
Java Panels and Layouts help
By Zookey in forum New To JavaReplies: 2Last Post: 01-30-2011, 12:06 PM -
problems with layouts !
By ron2794 in forum NetBeansReplies: 1Last Post: 12-15-2010, 01:23 AM -
Can you have multiple layouts using swing?
By fresh83 in forum New To JavaReplies: 2Last Post: 12-27-2009, 09:38 PM -
Layouts ?
By plodos in forum EclipseReplies: 3Last Post: 07-30-2007, 03:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks