setMaximumSize not working in java

后端 未结 4 1215
萌比男神i
萌比男神i 2020-12-19 10:06

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         


        
相关标签:
4条回答
  • 2020-12-19 10:27

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

    It's a known bug:

    • http://bugs.sun.com/bugdatabase/view_bug.do;?bug_id=6200438
    • http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4744281
    • http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4320050

    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.

    0 讨论(0)
  • 2020-12-19 10:27

    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.

    0 讨论(0)
  • 2020-12-19 10:41

    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 讨论(0)
  • 2020-12-19 10:45

    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();
    
    0 讨论(0)
提交回复
热议问题