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