Maciek Murawski
Maciek Murawski

Reputation: 444

Mouse wheel resizes JPanel and all inner components

Let's say I have JPanel, panelA and two JButtons inside it (button1 and button2). I want to add MouseWheelListener to JPanel, so when I make an event, all components will resize (become larger or smaller). I came up with this code:

for (Component comp : panelA.this.getComponents())
{
    if (comp instanceof JButton)
    {
        comp.setPreferredSize(new Dimension(
            (int) (PREFERRED_WIDTH * SCALE_WIDTH),
            (int) (PREFERRED_HEIGHT * SCALE_HEIGHT)));
    }
}

Values of SCALE_HEIGHT & SCALE_WIDTH are changing when I make an event.

My question is this: is it good? Should I set preferred size all of inner components or make something else?

Upvotes: 2

Views: 237

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347194

I was wracking my poor old brain trying to think of way to do this, when it occurred to me that this is a classic case for JXLayer (or JLayer under Java 7)

There use to be some really good examples, but they seem to have vanished into the ether

Upvotes: 3

Related Questions