SetMaximumSize not working in java

I have a Java program with JFrame

I use 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 practically miss the setMaximumSize() function

I read, and most likely it happened earlier

Is this a known mistake?

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

try it yourself and see what happens ...

early

PS ... please do not laugh at the names that I give my classes ... :)

+5
source share
3 answers

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

This is a known bug:

Perhaps you could use

 Ape.setResizable(false) 

instead

PS: This is an agreement to give class names starting with a letter and a letter with a small letter, and not vice versa.

+10
source

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(); 
+1
source

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); } }); 
0
source

All Articles