Java swing

The following code works fine in jdk1.3.1 But the JTabbedPane is not visible
when it is compiled in j2sdk1.4.0_03.
Can any one help.

import java.awt.;
import java.awt.event.
;
import java.util.;
import javax.swing.
;

public class TabbedPaneExample extends JApplet
{
JTabbedPane tabbedPane;
JPanel panel1;
JPanel panel2;
JPanel panel3;

TabbedPaneExample()
{
	super();
}

public static void main (String[] args)
{
               TabbedPaneExample tabbedPaneExample = new TabbedPaneExample ();
	tabbedPaneExample.init ();
	tabbedPaneExample.displayApp(tabbedPaneExample);
}

public void init()
{
	tabbedPane = new JTabbedPane();
	panel1 = new JPanel();
	panel1.add(new JLabel("one"));
	panel2 = new JPanel();
	panel2.add(new JLabel("two"));
	panel3 = new JPanel();
	panel3.add(new JLabel("three"));		

	tabbedPane.addTab("one", panel1);
	tabbedPane.addTab("two", panel2);
	tabbedPane.addTab("three", panel3);

	getContentPane().add(new JLabel("       "),BorderLayout.NORTH);
	getContentPane().add(new JLabel("       "),BorderLayout.WEST);
	getContentPane().add(new JLabel("       "),BorderLayout.EAST);
	getContentPane().add(new JLabel("       "),BorderLayout.SOUTH);
	getContentPane().add(tabbedPane, BorderLayout.CENTER);
}

public void displayApp(TabbedPaneExample applet)
{
	JFrame frameMain = new JFrame ("example");
	frameMain.getContentPane ().add (applet);
	frameMain.setVisible (true);
	frameMain.setBounds (50, 50, 670, 600);
	frameMain.setResizable (false);		
	frameMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}

Hi Pradeep,

I cannot see any problem - it compiles and runs perfectly.
I am using j2sdk version 1.4.2_01

Martyn

Hi the reason why u are not able to see is because u are making it visible before adding the applet. change the following function

public void displayApp(TabbedPaneExample applet)
{
JFrame frameMain = new JFrame (“example”);
frameMain.getContentPane ().add (applet);
frameMain.setVisible (true);
frameMain.setBounds (50, 50, 670, 600);
frameMain.setResizable (false);
frameMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

to

public void displayApp(TabbedPaneExample applet)
{
JFrame frameMain = new JFrame (“example”);
frameMain.getContentPane ().add (applet);
frameMain.setBounds (50, 50, 670, 600);
frameMain.setResizable (false);
frameMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frameMain.setVisible (true);
}

and it will work properly.

:slight_smile:

I was totally confused how to position the components in my desired location inside the panel…

After searching so many tutorials,finally i found this one and i got my solution…thanks a lot…

this form programming tutorials is really a shot in the arm of the beginners of java Swing

thank u to the author…

I was totally confused how to position the components in my desired location inside the panel…

After searching so many tutorials,finally i found this one and i got my solution…thanks a lot…

this form programming tutorials is really a shot in the arm of the beginners of java Swing

thank u to the author…