Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic

setSize and setMinimumSize don't seem to have any effect  RSS feed

 
Cate van Alphen
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

I'm having problems affecting the size of components. I have a dice object that extends JPanel and overrides the paintComponent method to display the appropriate image. I want to put several of these onto another JPanel. However the dice objects will only display a tiny bit. I have tried setSize and setMinimumSize on both the dice object, and the JPanel I'm putting them onto. It doesn't seem to make any difference.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
if the container for your dice object/s uses a layout manager (not null),
setPreferredSize(new Dimension(int,int));
should fix the problem



in the example, 'panel' uses a FlowLayout() (which is its default layout manager)
so, 'panel' will be looking for the Dice object's preferredSize to lay them
out correctly.

if you change to a null layout
panel.setLayout(null);
setPreferredSize() will have no effect - in this case you would need to create
a Dice object, then use dice.setSize() and dice.setLocation()
[ October 17, 2006: Message edited by: Michael Dunn ]
 
Cate van Alphen
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Report post to moderator
It works! Thanks so much.
 
koduru anusha
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
thanks a lot even my problem is solved
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!