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>
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>