java - How to add a picture onto JTabbedPane - on a null panel layout? -


i want implement 200 * 200 picture onto jtabbed pane layout src folder.

my issue nothing showing- no error no exception , no picture.

i dont think have declare directory , set private included in src folder.

import java.awt.*; import javax.swing.*;  import java.awt.event.keyevent; import javax.swing.imageicon; import javax.swing.jlabel; import javax.swing.jframe;    public class example1          extends jframe    {     private     jtabbedpane tabbedpane;     private     jpanel      panel1;      public example1()     {         // note: reduce amount of code in example, uses         // panels null layout.  not suitable         // production code since may not display correctly         // look-and-feel.          settitle( "program" );         setsize( 800, 400 );         setbackground( color.gray );          jpanel toppanel = new jpanel();         toppanel.setlayout( new borderlayout() );         getcontentpane().add( toppanel );          // create tab pages         createpage1();           // create tabbed pane         tabbedpane = new jtabbedpane();         tabbedpane.addtab( "tab page", panel1 );         toppanel.add( tabbedpane, borderlayout.center );     }      public void createpage1()     {         panel1 = new jpanel();         panel1.setlayout( null );          imageicon pic = new imageicon("test.png");         jlabel label = new jlabel (pic);         panel1.add(label);         label.setvisible (true);         label.setbounds( 200, 200, 200, 400 ); }  // main method things started     public static void main( string args[] )     {         // create instance of test application         example1 mainframe  = new example1();         mainframe.setvisible( true );       } } 

if want me provide more info please ask it.

don't use null layout (and ride of setbounds()) on panel.

the panel doesn't have preferred size swing thinks there nothing paint.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -