Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
Can a container have multiple layout managers?
smyle khanna
Ranch Hand
Posts: 54
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi ..
this question has 2 options true and false...
and i have searched a lot and every time i get mixed response for this..
plzz guide me through
Smyle
Joe Ess
Bartender
Posts: 9626
16
I like...
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Look at the method setLayout() in the
Java
Documentation for java.awt.Container. Does that answer your question?
[
How To Ask Questions On JavaRanch
]
Craig Wood
Ranch Hand
Posts: 1535
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
A container can have only one layout manager but may also contain components that each have a different layout manager.
import java.awt.*; import javax.swing.*; public class Layouts { public static void main(String[] args) { JPanel top = new JPanel(), mid = new JPanel(new GridBagLayout()), low = new JPanel(new GridLayout(1,0)), center = new JPanel(new GridLayout(0,1)); top.add(new JLabel("top panel")); top.setBorder(BorderFactory.createEtchedBorder()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0,2,0,2); gbc.weightx = 1.0; addComponents(new JLabel("label 1"), new JTextField(4), mid, gbc); addComponents(new JLabel("label 2"), new JTextField(4), mid, gbc); for(int j = 0; j < 4; j++) low.add(new JButton("button " + (j + 1))); center.add(top); center.add(mid); center.add(low); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(center); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } private static void addComponents(JLabel label, JTextField tf, JPanel p, GridBagConstraints gbc) { gbc.anchor = gbc.EAST; p.add(label, gbc); gbc.anchor = gbc.WEST; p.add(tf, gbc); } }
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Rueben or Clay??
Any chance that you will have a While X'mas?
Labels with Name in Javaranch Forum Site
Need IT Job in Canada
unable to access jsp pages
More...