This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes creating custom JComponent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "creating custom JComponent" Watch "creating custom JComponent" New topic

creating custom JComponent

David Shepherd
Ranch Hand

Joined: Mar 02, 2001
Posts: 35
I created a class by extending JPanel. The idea is to combine a JLabel and a JTextField and simply return a text field with a label already attached. The duo would live inside of a small JPanel. I'm having trouble settin the size of the JPanel so that it is only as large as the JLabel/JTextField combo.
I know some of the layout managers override sizing. Is there one that will allow me to explicitly set the size of this little JPanel and not allow the JPanel I put it in to resize it?
Angela Lamb
Ranch Hand

Joined: Feb 22, 2001
Posts: 156
FlowLayout will always use the preferred size of a component. BorderLayout will use the preferred size in the North, South, East, and West areas, but not in the center. GridBayLayout will use the preferred size, as long you set the fill property to none. BoxLayout will use either preferred height or width, depending on which alignment you set. You can find out more about layout managers at the Sun Swing tutorial.
David Shepherd
Ranch Hand

Joined: Mar 02, 2001
Posts: 35
Thank you very much.
I agree. Here's the link:
subject: creating custom JComponent
Similar Threads
best layout to use
Correct size of a Container
Regarding JTextfield and Jlabel
how to do validation using java swing?
Help sorting out what combination of layouts will provide the result I need