How to get a JTabbedPane to show up in app

G

Gil

Hi,

I've written a small java app. Created a JTabbedPane, but can't get
it to show in my window. Any tips?


import java.awt.*;
import javax.swing.*;


class First extends Frame {

public First() {
JTabbedPane jtp = new JTabbedPane();
jtp.addTab("Cities", new CitiesPanel());
jtp.addTab("Colors", new ColorsPanel());
jtp.addTab("Flavors", new FlavorsPanel());
add(jtp);
}

class CitiesPanel extends JPanel {

public CitiesPanel() {

JButton b1 = new JButton("New York");
add (b1);
JButton b2 = new JButton("London");
add (b2);
JButton b3 = new JButton("Hong Kong");
add (b3);
JButton b4 = new JButton("Tokyo");
add (b4);
}
}


class ColorsPanel extends JPanel {

public ColorsPanel() {

JCheckBox cb1 = new JCheckBox("Red");
add(cb1);
JCheckBox cb2 = new JCheckBox("Green");
add(cb2);
JCheckBox cb3 = new JCheckBox("Blue");
add(cb3);
}

}

class FlavorsPanel extends JPanel {

public FlavorsPanel() {

JComboBox jcb = new JComboBox();
jcb.addItem("Vanilla");
jcb.addItem("Vanilla");
jcb.addItem("Vanilla");
add(jcb);
}

}

public static void main(String args[]) {
System.out.println("First with JTabbedPane");
Frame appwin = new Frame();
appwin.setSize(new Dimension(300,200));
appwin.setLocation(250,250);
appwin.setTitle("An AWT-Based Application");
appwin.setVisible(true);

}



}
 
T

Thomas Weidenfeller

Gil said:
Hi,

I've written a small java app. Created a JTabbedPane, but can't get
it to show in my window. Any tips?


import java.awt.*;
import javax.swing.*;


class First extends Frame {

public First() {
JTabbedPane jtp = new JTabbedPane();

Mixing AWT and Swing components is a bad idea.

[...]
public static void main(String args[]) {
System.out.println("First with JTabbedPane");
Frame appwin = new Frame();

You are not instantiating your own subclass, just an empty Frame class.

BTW: Please consider asking beginner's questions in comp.lang.java.help,
and real GUI questions in comp.lang.java.gui.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top