Component that don't resize

S

stereat

Hi,

i'm writing a new component, that would show a recatangle with the same
size of the component. The matter is that, when i use the component
alone, all works right. When i use with other components the custom
component don't resize. What can be the problem? How can i solve it? I
need to add a component listener to my component?
I write the component's code extending a JPanel and overwriting the
paintComponent method. Here's the code of method:

<code>
public void paintComponent(Graphics g) {

super.paintComponent(g);

Insets insets = this.getInsets();
int currentWidth = this.getWidth() - insets.left - insets.right;
int currentHeight = this.getHeight() - insets.top - insets.bottom;

g.drawRect(insets.left, insets.top, currentWidth-1,
currentHeight-1);
}
</code>
 
R

Roedy Green

i'm writing a new component, that would show a recatangle with the same
size of the component. The matter is that, when i use the component
alone, all works right. When i use with other components the custom
component don't resize. What can be the problem? How can i solve it? I
need to add a component listener to my component?
I write the component's code extending a JPanel and

your component had better implement getMinumSize getMaximumSize and
GetPreferredSize. The ones your inheriting may be pretty lame.

You can do it with the shortcut setMinimumSize etc. Make sure you set
all three.

The layout manager will call these methods, decide on your size, and
call setSize to tell you how big to be.

Each time you paint you should check to see what your current size is.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
S

stereat

But more in general, what i need to do, to build a custom component
that works like others components respect to resizing, repositioning,
ecc?
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top