• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swings

 
D Mahapatra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir,
I have a problem with Swings-JTabbedPane. When I want to add a ButtonGroup component (which has two JRadioButtons added to it) to a JPanel with add() i.e, jp.add(bg), it shows error. So ultimately I can not add the JPanel to the JTabbedPane. But when I add the JRadioButtons directly to the JPanel and in turn, JPanel to JTabbedPane then there is no compilation error but there is runtime error stating NullPointerException on the line marked with '?' mark.
b1=new JRadioButton("Married");
b2=new JRadioButton("Unmarried");
bg=new ButtonGroup();
bg.add(b1);
bg.add(b2);
jp=new JPanel();
jp.add(b1,b2);
c.add(jp);
jtp.addTab("MS",ii,jp,"Marital Status"); ???
jtp.setSize(250,250);
jf.getContentPane().add(jtp);
Please, help.
 
Sayed Ibrahim Hashimi
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, did you initalize c? If you didnt then you might want to try:
c = getContentPane();
 
D Mahapatra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ibrahim Hashimi:
Hi, did you initalize c? If you didnt then you might want to try:
c = getContentPane();

Hi!, Thanks for the response. Of course, I had initiallized Container c. The code works fine without including this tabbed pane. So that's why I am puzzled. And of course, i know a round about way to do this. But I am basically interested to know the basic fault in this code. Bye.
Debasis
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!