Making a Frame Non-Resizable in Java



yes u can make the applet program resizable.

In java  there is a method called setResizable method. This method which is responsible for modifying the size of the window on  your applet/awt program   .
In your program, Assume that you have taken a boolean value false for method setResizable then the frame will be non-resizable otherwise frame will be resizable, The setResizable method is the method of Frame class.

Here is the few related methods views of the Frame Class Supported by the api of jdk1.5



SW_RESIZE_CURSOR

@Deprecated
public static final int SW_RESIZE_CURSOR

Deprecated. replaced by Cursor.SW_RESIZE_CURSOR.



SE_RESIZE_CURSOR


@Deprecated

public static final int SE_RESIZE_CURSOR

Deprecated. replaced by Cursor.SE_RESIZE_CURSOR.


NW_RESIZE_CURSOR

@Deprecated
public static final int NW_RESIZE_CURSOR

Deprecated. replaced by Cursor.NW_RESIZE_CURSOR.


NE_RESIZE_CURSOR

@Deprecated
public static final int NE_RESIZE_CURSOR

Deprecated. replaced by Cursor.NE_RESIZE_CURSOR.


N_RESIZE_CURSOR

@Deprecated
public static final int N_RESIZE_CURSOR

Deprecated. replaced by Cursor.N_RESIZE_CURSOR.



S_RESIZE_CURSOR

@Deprecated
public static final int S_RESIZE_CURSOR

Deprecated. replaced by Cursor.S_RESIZE_CURSOR.


W_RESIZE_CURSOR

@Deprecated
public static final int W_RESIZE_CURSOR

Deprecated. replaced by Cursor.W_RESIZE_CURSOR.


E_RESIZE_CURSOR

@Deprecated
public static final int E_RESIZE_CURSOR

Deprecated. replaced by Cursor.E_RESIZE_CURSOR.



isResizable

public boolean isResizable()

Indicates whether this frame is resizable by the user. By default, all frames are initially resizable.

Returns:
true if the user can resize this frame; false otherwise.


setResizable

public void setResizable(boolean resizable)

Sets whether this frame is resizable by the user.

Parameters:
resizable – true if this frame is resizable; false otherwise.


setState

public void setState(int state)

Sets the state of this frame (obsolete).

In older versions of JDK a frame state could only be NORMAL or ICONIFIED. Since JDK 1.4 set of supported frame states is expanded and frame state is represented as a bitwise mask.

For compatibility with old programs this method still accepts Frame.NORMAL and Frame.ICONIFIED but it only changes the iconic state of the frame, other aspects of frame state are not affected by this method.

Parameters:
state – either Frame.NORMAL or Frame.ICONIFIED.
See Also:
getState(), setExtendedState(int)


setExtendedState

public void setExtendedState(int state)

Sets the state of this frame. The state is represented as a bitwise mask.

* NORMAL
Indicates that no state bits are set.
* ICONIFIED
* MAXIMIZED_HORIZ
* MAXIMIZED_VERT
* MAXIMIZED_BOTH
Concatenates MAXIMIZED_HORIZ and MAXIMIZED_VERT.

Note that if the state is not supported on a given platform, nothing will happen. The application may determine if a specific state is available via the java.awt.Toolkit#isFrameStateSupported(int state) method.

Parameters:
state – a bitwise mask of frame state constants
Since:
1.4
See Also:
getExtendedState(), Toolkit.isFrameStateSupported(int)



getState

public int getState()

Gets the state of this frame (obsolete).

In older versions of JDK a frame state could only be NORMAL or ICONIFIED. Since JDK 1.4 set of supported frame states is expanded and frame state is represented as a bitwise mask.

For compatibility with old programs this method still returns Frame.NORMAL and Frame.ICONIFIED but it only reports the iconic state of the frame, other aspects of frame state are not reported by this method.

Returns:
Frame.NORMAL or Frame.ICONIFIED.
See Also:
setState(int), getExtendedState()



getExtendedState

public int getExtendedState()

Gets the state of this frame. The state is represented as a bitwise mask.

* NORMAL
Indicates that no state bits are set.
* ICONIFIED
* MAXIMIZED_HORIZ
* MAXIMIZED_VERT
* MAXIMIZED_BOTH
Concatenates MAXIMIZED_HORIZ and MAXIMIZED_VERT.

Returns:
a bitwise mask of frame state constants
Since:
1.4
See Also:
setExtendedState(int)
if u want overview all the api of Frame follow the link below

Api of Frame

illustrating an example on java.awt.Frame class

import java.awt.*;
import java.awt.event.*;

public class AwtFrameNonResizable{
public static void main(String[] args){
Frame frame = new Frame(“Non Resizable Frame”);
Image icon = Toolkit.getDefaultToolkit().getImage(“your pic.gif”);
frame.setIconImage(icon);
Label lbl = new Label(“The View of the Image. “,Label.CENTER);
frame.add(lbl);
frame.setResizable(false);
frame.setSize(400,400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
Frame frame = (Frame)we.getSource();
frame.dispose();
}
});
}
}

Random Posts

  • Hibernate Interview Questions
  • Define JSP
  • Using Serialization
  • Java-Jdbc Questions
  • Define Local Interfaces

Post a Comment