I try to create a JTabbedPane object, but it does not work. What is wrong??
Mike
======Codelist.java========
import java.awt.*;
import javax.swing.*;
public class Codelist extends JPanel {
public JTabbedPane Codelist(String var) {
JTabbedPane pn = new JTabbedPane();
JPanel p1 = new JPanel(new GridBagLayout());
p1.add(new JButton(var));
pn.addTab("tab1",p1);
return pn;
}
public static void main(String[] args){
final JFrame frame = new JFrame("test");
frame.addWindowListener(new WindowAdapter()
{public void windowClosing(WindowEvent e) {System.exit(0);}});
JPanel p = new JPanel(new GridBagLayout());
Codelist c = new Codelist("but1");
p.add(c);
frame.getContentPane().add(p);
frame.pack();
frame.show();
}
}
> I try to create a JTabbedPane object, but it does not work. What is wrong??
> Mike
[quoted text clipped - 5 lines]
> public class Codelist extends JPanel {
> public JTabbedPane Codelist(String var) {
here is your problem. This is not the constructor. A constructor does not
return any value.
public Codelist(String var) {} is what you wanted to do, right?
> JTabbedPane pn = new JTabbedPane();
> JPanel p1 = new JPanel(new GridBagLayout());
[quoted text clipped - 8 lines]
> JPanel p = new JPanel(new GridBagLayout());
> Codelist c = new Codelist("but1");
you call the default constructor here. On c you could invoke
Codelist("but1") and get what you want. But that is NOT the way you should
do such a thing! See below...
> p.add(c);
> frame.getContentPane().add(p);
> frame.pack();
> frame.show();
> }
> }
Try:
import everything.you.need;
public class TestCodeList {
// do not subclass Swing components for a work that this method can do
private static createCodeList(String var) {
JTabbedPane pn = new JTabbedPane();
JPanel p1 = new JPanel(new GridBagLayout());
p1.add(new JButton(var));
pn.addTab("tab1",p1);
return pn;
}
public static void main(String[] args){
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
JPanel p = new JPanel(new GridBagLayout());
JTabbedPane c = createCodeList("but1");
p.add(c);
frame.getContentPane().add(p);
frame.pack();
frame.show();
}
}
Sebastian
Mike - 31 May 2004 21:51 GMT
> > I try to create a JTabbedPane object, but it does not work. What is
> wrong??
[quoted text clipped - 61 lines]
> }
> }
OK, thanks that works!
Mike
>I try to create a JTabbedPane object, but it does not work.
You get people's backs up when you say "doesn't work". It sound like
you are playing dumb blond. Be more specific. Give an error message.
Say what it did and what you wanted it to do.
see http://mindprod.com/jgloss/newsgroups.html

Signature
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.