Common features of the "Java Language programming Fundamentals"--swing GUI component

Source: Internet
Author: User

</pre><pre name= "code" class= "HTML" >package chapter12;import java.awt.color;import java.awt.FlowLayout; Import Java.awt.font;import java.awt.gridlayout;import Javax.swing.jpanel;import Javax.swing.jbutton;import Javax.swing.jframe;import javax.swing.border.lineborder;//Line Box Import javax.swing.border.titledborder;// Title Box @suppresswarnings ("Serial") public class Testswingcommonfeatures extends Jframe{public testswingcommonfeatures () { JPanel P1 = new JPanel (new FlowLayout (flowlayout.left,2,2)); JButton jbtleft = new JButton ("left"); JButton jbtcenter = new JButton ("CENTER"); JButton jbtright = new JButton ("right"); Jbtleft.setbackground (Color.White); Jbtcenter.setforeground (Color.green); Jbtright.settooltiptext ("The right button");p 1.add (jbtleft);p 1.add (jbtcenter);p 1.add (jbtright); P1.setborder (New Titledborder ("three Buttons")),//-------------------------------------//font largefont =new Font (" Timesroman ", font.bold,20);//font JPanel p2 = new JPanel (new FlowLayout (flowlayout.left,5,5)); JButton jbtred = new JButton ("Red"); JButton Jbtorange = new JButton ("Orange"); Jbtred.setfont (Largefont); Jbtred.setbackground (color.red); Jbtorange.setforeground (Color.orange); Jbtorange.settooltiptext ("This is a orange button");p 2.add (jbtred);p 2.add ( Jbtorange);p 2.setBorder (New Lineborder (color.green,4)) and/or the next line overrides P2.setborder (New Titledborder ("a"));p 2.setLayout ( New GridLayout (1,2,1,10)); SetLayout (new FlowLayout (flowlayout.left,30,30)); SetLayout (new GridLayout (1,2,5,10));// The next line has a new setlayout this same setlayout is overwritten and does not show add (p1); add (p2);} public static void Main (string[] args) {JFrame frame = new Testswingcommonfeatures (); Frame.settitle ("Test swing common FEA Frame.setsize (tures); Frame.setlocationrelativeto (null);//center frame.setvisible (true); Frame.setdefaultcloseoperation (Jframe.exit_on_close);}}

Show

Font fonts

Color colors

Border Box




Common features of the "Java Language programming Fundamentals"--swing GUI component

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.