aspose file tools*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "creating custom JComponent" Watch "creating custom JComponent" New topic
Author

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.

http://web2.java.sun.com/docs/books/tutorial/uiswing/layout/using.html
David Shepherd
Ranch Hand

Joined: Mar 02, 2001
Posts: 35
Thank you very much.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating custom JComponent