Fixed size JPanel subclass

C

Chris R.

I'm trying to create a simple fixed-size, image-displaying JPanel
subclass -- what I want to do is to be able to create it with a preset
(albeit alterable manually) size and have it just display an Image of
some kind.

What methods of JPanel do I have to override to maintain total control
over the component's size?
 
L

Liz

Chris R. said:
I'm trying to create a simple fixed-size, image-displaying JPanel
subclass -- what I want to do is to be able to create it with a preset
(albeit alterable manually) size and have it just display an Image of
some kind.

What methods of JPanel do I have to override to maintain total control
over the component's size?

JPanel jones = new JPanel();
jones.setBounds(new Rectangle(0, 0, 500, 500));
 
C

Chris R.

Liz said:
JPanel jones = new JPanel();
jones.setBounds(new Rectangle(0, 0, 500, 500));

Is it really that easy?

Every time I think I have control over the layout of these things,
something comes along and makes me wonder. So, with this I won't run
into layout manager noise about the size of this?
 
G

Guest

Chris R. said:
I'm trying to create a simple fixed-size, image-displaying JPanel
subclass -- what I want to do is to be able to create it with a preset
(albeit alterable manually) size and have it just display an Image of
some kind.

What methods of JPanel do I have to override to maintain total control
over the component's size?

I think you can create your own subclass of JPanel and override the
getMinimumSize(), getMaximumSize(), and getPreferredSize() methods to
return whatever dimensions you would like.
 
C

Christian Kaufhold

I think you can create your own subclass of JPanel and override the
getMinimumSize(), getMaximumSize(), and getPreferredSize() methods to
return whatever dimensions you would like.

There is no need to subclass for that. You can just use setMinimumSize/
setPreferredSize/setMaximumSize.



Christian
 
R

Roedy Green

There is no need to subclass for that. You can just use setMinimumSize/
setPreferredSize/setMaximumSize.

I have never got those methods to work. I always gave up and did an
override. Is there some catch?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top