Re: Scaling/Resizing 2D graphics in JPanel



steve_marjoribanks@xxxxxxxxxxx wrote:

Basically, I want
the graphical contents of the JPanel to resize as the JPanel is resized
so as to fill the available space.

I subclass JPanel and override JComponent's doLayout method. Then I call getWidth and getHeight to get the size of the panel.


My initial thoughts were that this could be done with a getSize()
method or similar on the JPanel and then basing the 'canvas' size
around these values and effectively recalculating the coordinates of
each line etc each time the JPanel is resized.

You shouldn't have to recalculate your coordinates, assuming you want everything to scale the same. You can just calculate a new AffineTransform based on the new size, apply it to the Graphics2D and it will scale everything for you.

--
Judy Szikora, Apprisant Technologies Inc.
http://www.apprisant.com
.



Relevant Pages

  • Re: Java swing JPanel painting
    ... I override the JPanel paintComponent() method to plot some data. ... until I resize the window (causing the JPanel to ... I added a button which calls repaint() on the panel. ...
    (comp.lang.java.programmer)
  • Re: Java swing JPanel messed up
    ... I override the JPanel paintComponent() method to plot some data. ... until I resize the window (causing the JPanel to ...
    (comp.lang.java.gui)
  • Re: Java swing JPanel messed up
    ... I override the JPanel paintComponent() method to plot some data. ... until I resize the window (causing the JPanel to ... I added a button which calls repaint() on the panel. ...
    (comp.lang.java.gui)
  • Re: check-boxes in JTable
    ... set of 2-3 there's atleast one which is still givin problem. ... JPanel ... now when i resize the frame, only frame gets resized while the table ...
    (comp.lang.java.gui)
  • Java swing JPanel painting
    ... I override the JPanel paintComponent() method to plot some data. ... until I resize the window (causing the JPanel to ... I added a button which calls repaint() on the panel. ...
    (comp.lang.java.programmer)