Swing Common components

Source: Internet
Author: User

Swing basic components. * Swing Top Container class: JFrame jdialog japplet the principle of using the above container: 1. To be displayed on the screen, each GUI component must be a "container-level" (a container-level is part of a component tree that has a top-level container as the root). 2. Each GUI component can belong to only one container. If a component is already in a container, trying to add to another container, remove the component from the previous container and add it to the latter component. 3. Each top-level container has a content panel (Content_pane) and each component is placed in the content_pane of the top-level container. 4. The menu bar is located in the top-level container, but is outside Content_pane. public static void Main (string[] args) {Javax.swing.SwingUtilities.invokeLater (New Runnable () to book a job for the event distribution thread {public void Run () {new class name (). Createandshow (); }});} JFrame:Setjmenubar (menubar); Add a menu bar to a form pack (); All components display the available setsize () SetBounds () in the preferred size instead Setlocationrelativeto (null); Place the form in the middle of the screen jframe.setdefaultlookandfeeldecorated (true); Displays the custom icon with the window decoration provided by the specified program skin to be called before the form is created Seticonimage (New ImageIcon (Imgurl). GetImage ()); Custom Get Image function: protected static Image getimage () {Java.net.URL imgurl= class name. Class.getResource ("image file path"); Usually create a picture folder inside Binif (imgurl!=null) return new ImageIcon (Imgurl). GetImage (); else return null; }the Dimension class encapsulates the width and height of components in a single object (accurate to integers). This class is associated with a property of a component. Some methods defined by the Component class and the LayoutManager interface will return the Dimension object. setbackground Setting the background color of an object jcomponent:In addition to the above 3 top-level containers, all components that begin with J inherit from the Jcomponent,jcomponent inheritance to the Container,container inheritance to component. settooltiptext () hint string SetBorder () draw a border Uimanager Set Appearance uimanager.put ("Swing.boldmetal", boolean.false); JButton:setmnemonic () setting keyboard keys setverticaltextposition () Sethorizontaltextpositon () sets the vertical, horizontal position of the text on the button relative to the icon Setactioncommand () Set the action command for the button setenabled (False) Disable button Setdefaultbutton () Set default button press ENTER = Clicked Jcheckbox:setselected (True) the check box is selected by default Jradiobutton:Create a radio button group object with the Buttongroup class, then the Add radio button, which is a single selection in this group, or a button to add in Content_pane JTextField:SetText () getText () sethorizontalalignment () to set text alignment in a text box JPasswordField:Setechochar () sets the visible character of the password box JComboBox:setselectedindex () Set default options AddItem () Insertitemat () JSlider:specify direction, minimum, maximum, initial value when creating setmajortickspacing () Set primary tick interval setminortickspacing () set the sub-scale interval Setpaintticks () whether to draw tick marks on the slider Setpaintlabels () whether to draw a label on the slider Customize the label that displays the scale value, with Hashtable<integer,jlabel>, and then setlabeltable () + to the slider, Setpaintlabels (True) to display. JSpinner:first define a Spinnerlistmodel to add a string, and then join the spinner JMenu:Getaccessiblecontext (). Setaccessibledescription () sets the accessible description of this object SetAccelerator () Set keyboard key combination addseperator () Add split line JList:Create the model first, then join the list, generally use defaultlistmodel,listmodel.addelement (), or you can directly add the list contents (string[]) setselectionmode () setting list item selection Properties setlayoutorientation () Setting the arrangement direction Setvisiblerowcount () sets whether all list items are visible JLabel:Setopaque () is transparent setlablefor () to describe another component with a label JProgressBar:SetCursor () sets the mouse to display the wait state when the cursor is over the container SetValue () sets the current value setstringpainted () display percentage setminimum () setmaximum () setindeterminate () set to indeterminate progress bar jseparator:setorientation () sets its orientation and can specify the direction when it is created

Swing Common components

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.