Component 2 Creating a Tab object

Source: Internet
Author: User

Create a Tab object to associate to a small form object (JPanel)

However, the use of Jpanel objects is not visible, you need to use the border and set the color to be seen

After the Jpnael object is associated with a tab object, you do not need to set the small form object (the small form object and its associated component (which is a whole) automatically match the tab

You need to inherit the JPanel class in the class of the component that is associated with the small form (small form)

The thought is similar to the component thought, but the fundamental thought is different, the object oriented,

 Packagecn.lovo.day03_30;ImportJava.awt.Image;ImportJavax.swing.ImageIcon;ImportJavax.swing.JButton;ImportJavax.swing.JLabel;ImportJavax.swing.JPanel; Public classMoneyjpanelextendsjpanel{ PublicMoneyjpanel () { This. setlayout (NULL);
JButton JB=NewJButton ("name"); Jb.setbounds (60, 150, 80, 25); This. Add (JB); Image img=NewImageIcon ("Ming/dsws.jpg"). GetImage (); IMG= Img.getscaledinstance (120, 100, 1); JLabel JLA=NewJLabel (NewImageIcon (IMG)); Jla.setbounds (35, 30, 120, 100); This. Add (JLA); } }

 Packagecn.lovo.day03_30;ImportJavax.swing.JLabel;ImportJavax.swing.JPanel;ImportJavax.swing.JTextField; Public classNewjpanelextendsjpanel{ PublicNewjpanel () { This. setlayout (NULL); JTextField T=NewJTextField (); T.setbounds (50, 40, 120, 30);  This. Add (t); JLabel JLA=NewJLabel ("OK"); Jla.setbounds (80, 100, 80, 25);  This. Add (JLA); }}

1 ImportJavax.swing.JFrame;2 ImportJavax.swing.JTabbedPane;3 4  Public classTabedframeextendsjframe{5      PublicTabedframe ()6     {7         8           This. setlayout (NULL);9          Ten         //Create a Tab object OneJTabbedPane JTB =NewJTabbedPane (jtabbedpane.left); AJtb.setbounds (80, 30, 250, 250); -          This. Add (JTB); -          the          -          //setting tab labels and containers -Jtb.add ("News",NewNewjpanel ()); -Jtb.add ("Finance",NewMoneyjpanel ()); +          -          +          This. setvisible (true); A          This. SetSize (500,400); at          This. setvisible (true); -          This. setdefaultcloseoperation (3); -          This. Setlocationrelativeto (NULL); -  -          -     } in      Public Static voidMain (string[] args) { -          toTabedframe TA =Newtabedframe (); +  -     } the  *}

Component 2 Creating a Tab object

Related Article

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.