I've made a game using a jFrame with components. Is there a way that I can make the JFrame bigger, but using a square aspect so that the length always equals the width when being dragged?
Any help is appreciated.
Cheers
I've made a game using a jFrame with components. Is there a way that I can make the JFrame bigger, but using a square aspect so that the length always equals the width when being dragged?
Any help is appreciated.
Cheers
You could implement the ComponentListener and have something like this
@Override
public void componentResized(ComponentEvent arg0) {
Rectangle b = arg0.getComponent().getBounds();
arg0.getComponent().setBounds(b.x, b.y, b.width, b.width);
}
and use it for your JFrame. The only thing is, with JFrame, it does not raise this event till the mouse is released. If you want to see the changes as you are dragging the mouse, you'll have to use a JPanel and use this ComponentListener for it rather than the JFrame and fill the frame with the panel.
You could try something like this:
public void componentResized(ComponentEvent e) {
System.out.println("i have changed size applying aspect ratio now.");
setSize(getWidth(), getWidth());
repaint();
}
This is a little unintuitive thou as it does the resize after the component has been resized.