• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating custom JComponent

 
David Shepherd
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic