background:The first step is to understand the hierarchy in the framework jframe.The hierarchical distribution and relative relationships in JFrame are:The bottom is: jrootpane; the second layer is: Jlayerpane, which contains a layer of ContentPane (the default is opaque), is also what we often say the content panel. So the most common control we drag and drop is on the ContentPane layer. The top is: GlassPane (which is transparent by default), then here's a method: principle: We put the pictur
01. The first methodint windowwidth = Frame.getwidth (); Get window widthint windowheight = Frame.getheight (); Get window HeightToolkit kit = Toolkit.getdefaulttoolkit (); Defining the ToolkitDimension screensize = Kit.getscreensize (); Get the size of the screenint screenwidth = Screensize.width; Gets the width of the screenint screenheight = Screensize.height; Gets the height of the screenFrame.setlocation (SCREENWIDTH/2-WINDOWWIDTH/2, SCREENHEIGHT/2-WINDOWHEIGHT/2);//
About Modal Forms
Only JDialog in Swing can be set to a Modal form, whose methods can be passed in a constructor (such as "JDialog (Frame owner, Boolean Modal)"), or by using the Setmodal (Boolean) method, which A method is inherited from the Dialog class.
In the JFrame class, the Modal form cannot be set through a method such as JDialog, where a friend tries t
How to set the center position of the Main Window in Java Swing
01. method 1
Int required wwidth = frame. getWidth (); // obtain the window width.Int required wheight = frame. getHeight (); // get the window heightToolkit kit = Toolkit. getdefatooltoolkit (); // define the ToolkitDimension screenSize = kit. getScreenSize (); // obtain the screen sizeInt screenWidth = screenSize. width; // obtain the screen
Java online chat project version 0.2 creates client forms, and uses swing (User Interface Development Kit) and awt (Abstract Window Toolkit) BorderLayout layout to set the size of JPanel, which is different from GridLayout layout,
The Code is as follows:
Package com. swift; import java. awt. borderLayout; import java. awt. color; import javax. swing. JButton; imp
); //Auto-Adjust individual panels with compressionpack (); Setdefaultcloseoperation (jframe.exit_on_close);//Click the Close button while exiting the programSetVisible (true); } Public Static voidMain (string[] args) {//don't forget to create a Form object, or you can call other methods with a build object such as Launchframe () NewChatclientframe (); }}With a grid layout, the size of multiple jpanel is the same because the mesh is fixed in sizeIf you want to adjust the size of the J
01. The first methodint windowwidth = Frame.getwidth (); Get form widthint windowheight = Frame.getheight (); Get form HighToolkit kit = Toolkit.getdefaulttoolkit (); Defining the ToolkitDimension screensize = Kit.getscreensize (); Get the size of the screenint screenwidth = Screensize.width; Gets the width of the screenint screenheight = Screensize.height; Gets the height of the screenFrame.setlocation (SCREENWIDTH/2-WINDOWWIDTH/2, SCREENHEIGHT/2-WINDOWHEIGHT/2);//
Swing tip. Set the global font (Sun JDK)Why?Because the default font display in Java is uglyBecause skin such as jgoodies does not support Chinese characters by defaultBecause jdk1.4 has a serious bug in mapping Chinese fonts, anyone who has used idea knows thatBecause only sun's JDK is available, IBM's and Bea's are not suitable for running the client.If you are smart ....
//
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.