2013年9月22日星期日

Set window size

java I would like to add to the window adjustment range , that is, can adjust to a maximum value, the minimum can be adjusted to a certain value , the code how to achieve ?
------ Solution ---------------------------------------- ----

  
  
buddy I want is inside the code . Do not you write me ?  
if(frame.getWidth() > 800 || frame.getHeight() > 600){
    frame.setPreferredSize(new Dimension(800,600));
    frame.pack();
}

so simple that he can not write ?
------ For reference only -------------------------------------- -
public void setMinimumSize (Dimension minimumSize)
------ For reference only ------------------------ ---------------
set the maximum public Dimension getMaximumSize ()
minimum getMinimumSize ()
------ For reference only ---------------------------- -----------
frame.addComponentListener(new ComponentAdapter(){
    @Override public void componentResized(ComponentEvent e){
        // 如果frame的大小超过了,重新设置frame的大小。
    }
});

------ For reference only --------------------- ------------------






buddy I want is inside the code . Do not you write me ?
------ For reference only -------------------------------------- -

  
  
buddy I want is inside the code . Do not you write me ?  

a judge sentences only, exceeds the maximum, put the width and height is set to the maximum force , less than the minimum will be set to the minimum.
------ For reference only -------------------------------------- -

    
    
buddy I want is inside the code . Do not you write me ?          
  
if(frame.getWidth() > 800 || frame.getHeight() > 600){
    frame.setPreferredSize(new Dimension(800,600));
    frame.pack();
}
  
so simple that he can not write ?  

I'm just beginning to learn java I wrote above you have not used your code above can be achieved, but there is BUG, windows can still be pulled Japan pull a small , sometimes it can
------ For reference only ---------------------------------------
The problem is not one size JavaBeans bound property , can not monitor size changes.
The above code just write exceeds the maximum size of the how to do,
write the result of the mouse can drag big , becomes an open back.

没有评论:

发表评论