6

I hava a java program with a JFrame

I am using absolute positioning

here is my main function

public static void main(String[] args) {
    ape Ape = new ape();
    Ape.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Ape.setSize(1000,1000);
    Ape.setMinimumSize(new Dimension(1000,1000));
    Ape.setMaximumSize(new Dimension(1000,1000));
    Ape.setVisible(true);
}

When I run the program I try to resize it and make the window smaller but I can't

when I try to make the window bigger it works fine I basicly skips the setMaximumSize() function

I have read around and aparently this has happened before

is this a known bug?

if so I heard I could make a Window Listener, when I tried it I implemented the functions that WindowListener needed but could not find anything to solve my problem

please try this yourself and see what happens...

thanks in advance

PS... please don't laugh about the names I give my classes... :)

4 Answers4

13

see http://forums.sun.com/thread.jspa?threadID=5342801:

It's a known bug:

Maybe you could use

Ape.setResizable(false)

instead?

PS: It's a convention to give classes names that start with a capital letter and variables ones with a small letter, not vice versa.

Besi
  • 22,579
  • 24
  • 131
  • 223
thejh
  • 44,854
  • 16
  • 96
  • 107
  • thanks for the report and the Ape.setResizable is basicly what I wanted thanks –  Oct 30 '10 at 23:28
  • I am searching if this bug is resolved. I am using jdk1.6.0_45 (App was developed years ago and I am maintaining it). Is it still a bug? – gengencera May 09 '18 at 06:23
1

In my case I used the following and it worked:

    Dimension newDim = new Dimension(width, height);

    label.setMinimumSize(newDim);
    label.setPreferredSize(newDim);
    label.setMaximumSize(newDim);
    label.setSize(newDim);
    label.revalidate();
Johntor
  • 587
  • 11
  • 26
  • I don't know how to say thanks to you .. thankyou thankyou so much. You saved my face and day. revalidate is the key. – Suresh Atta Nov 11 '16 at 22:46
1

For Netbeans user try to set values for the maximum frame in setMaximizedBounds() click in properties of frame you will find an option to define values for setMaximizedBounds.

A.Aleem11
  • 1,844
  • 17
  • 12
0

I fixed it like this :

    frame.setBounds(0, 0, 1480, 910);
    frame.setMinimumSize(new Dimension(1200, 799));
    frame.setMaximumSize(new Dimension(1480, 910));
    frame.setPreferredSize(new Dimension(1480, 910));
    frame.setLocationRelativeTo(null);
    frame.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            double w = frame.getSize().getWidth();
            double h = frame.getSize().getHeight();
            if(w > 1480.0 && h > 910.0){
                frame.setSize(new Dimension(1480, 910));
                frame.repaint();
                frame.revalidate();
            }

            super.componentResized(e);
        }

    });
Coder ACJHP
  • 1,940
  • 1
  • 20
  • 34