aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Frame SIze Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Frame SIze" Watch "Frame SIze" New topic
Author

Frame SIze

Khurram Fakhar
Ranch Hand

Joined: May 29, 2000
Posts: 65
Hi ppl,
if we create some frame then by double clicking it usually expand it to default screen size.
what if i want to restrict it ?
there is a method of setRisizable but after doing setResizable false of specific frame , it doesn't allow it to resze but still it can expand it to full screen size
waiting for reply
regards
khurram fakhar
Anh Nguyen
Greenhorn

Joined: Jan 24, 2001
Posts: 18
setResizable the main container will result the whole program will not be resized ( nor expand, minimize, maximize) at all . Is that what you want ?
Ex code :
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Test extends JFrame{
public Test(){
super("Test resize");
Container c = getContentPane();
JPanel panel1 = new JPanel();
JLabel label1 = new JLabel("Panel 1", SwingConstants.LEFT);
panel1.add(label1);
c.add(panel1,BorderLayout.WEST);
JPanel panel2 = new JPanel();
JLabel label2 = new JLabel("Panel 2",SwingConstants.CENTER);
panel2.add(label2, BorderLayout.CENTER);
c.add(panel2);
setSize(400,300);
setResizable(false);
show();
}//end no-argument constructor
public static void main(String [] args){
Test app = new Test();
app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}//end main
}//end program

------------------
... No one can escape .......
Heavenly Evil Knight


... No one can escape .......<BR><B>Heavenly Evil Knight</B>
Khurram Fakhar
Ranch Hand

Joined: May 29, 2000
Posts: 65
Thanx Anh Nguyen, for ur prompt reply
but what if , there is only awt context and not swing. ?
and that window can be minimized but shouldn't be maximzed to fit in the whole screen ?
regards
khurram
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Khurram,
setResizable(false) works with either AWT or Swing... it is a method of Frame and since JFrame extends Frame it is inherited...
Using setResizable() doesn't affect the window being minimized, it is called being Iconified in the Java documentation... However, if you are saying you don't want to be able to disable the maximize button on the window, but still want to be able to change the size of the window (by dragging on it's borders) then you are out of luck... setResizable() is the only way to go. ( Other than having some method the user can call via a component that calls the setSize() method... but that would be really clunky and alot harder to use... )
HTH,
-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Khurram Fakhar
Ranch Hand

Joined: May 29, 2000
Posts: 65
hi Nathan Pruett,
let it be more simple ,
well i create a frame which is of size 400 X 400
now when u double click its blue menue ,it expands that frame on complete screen .. RITE ?
now what if i dont want it to be maximised ? i just want it to be of the same size as i declared in its constructor.
in this case setResizable is also helpless..
regards
khurram
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Khurram,
I didn't know double clicking on the blue bar makes a window fill the screen, but I tried it (with my browser window) and it works... However, when I try it on a Frame with setResizable(false) in it, it does not resize... setResizable(false) doesn't let you resize the screen by pulling on the edges, by pushing the maximize button(in fact, it is grayed out, or by double clicking on the blue bar, however it will still let you minimize it (i.e. iconify it) to the taskbar... Isn't this the behavior you wanted? I am using JDK 1.3 and here is the code I tested it on...

HTH,
-Nate
Khurram Fakhar
Ranch Hand

Joined: May 29, 2000
Posts: 65
hi Nate
what if i want only a minimize button on menubar but NOT maximize button ?
regards
khurram
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Khurram,
Then you are out of luck! Those buttons are put there via MS API system code which the AWT uses to create a native system level window. I think they are required for most MS Windows windows (there are exceptions (if I remember correctly) like full-screen apps and windows without menubars) but as for how you would get your Java app to show up in one of these windows I am not sure... it would take quite a bit of work in VC++ and JNI... (neither of which I have used much) even if it is possible...
HTH,
-Nate
Khurram Fakhar
Ranch Hand

Joined: May 29, 2000
Posts: 65
Hi nathan,
Actually i m working on web based chat modules.
The code u written above , i already tried that in applet but it was not working , but in application it works , e.g
with jdk1.1.8 maximize button is not visible but with jdk1.2 there will only left close button up there in menu.
I donno why it is not working with applet but with application

if u have any clue , kindly do tell me
Khurram fakhar
Grant Crofton
Ranch Hand

Joined: Nov 08, 2000
Posts: 154
How can it work with an applet, it has no window of it's own.. I guess that's not what you mean.
You could always check the frames's size and resize it if it's different to the size you want - in paint() will work, as this gets called after the frame's resized.
However, this produces some dodgy-looking flashy effects when someone tries to stretch the window, but it gets the job done. All the button will still be in the window bar, of course.
Khurram Fakhar
Ranch Hand

Joined: May 29, 2000
Posts: 65
I think i didn't convey the proper scenario,
As i m working on a web based chat module, so on double clicking some nick i open a private chat (one-one chat) in another small window. THis window extends frame and it has all 3 buttons with it like minimize,maximize and close. I dont want user to maximize that private window.
Now code which is being discussed (written above by nathan) works fine with application but not with applet.
I tried that code already in applet, as it is very basic thing to do, but it was not working , but above written code is an application and it works fine, as there is maximize button of menubar is disable .. but with applet , all 3 icons r there in menubar ..
Now kindly throw some light on it.
Regards
khurram fakhar
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Khurram,
Okay! I know what you need now! You need to take the WindowAdapter out of the TestResizable constructor. Calling System.exit() causes problems in Applets... so your new TestResizable constructor should look like this :

Then, in an applet, do something like this :

Instead of making the windowClosing() event do a System.exit() you would make the frame invisible with setVisible( false ).
HTH,
-Nate
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Frame SIze