Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem to show dynamic Tabs  RSS feed

 
Shanmugam Muthukumarasamy
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have situation like, I have to show four different type of Tabbed panes based on the values which I am selecting from a combo box. I have four different values in the combo box. When I started with two values I could show the corresponding two different tabbed panes with out any problem, when I designed the third tabbed pane and trying to incorporate with the existing code, It is not showing that pane properly, it is messing up the existing panes also. Depends on the value I am selecting from the combobox I am trying to remove the other pane to show only one pane that corresponds to the value I had chosen. Here is my code:
void CboInspectionType_ItemSelected(ActionEvent evt)
{
//System.out.println("Item Selected : "+CboInspectionType.getSelectedItem());
String selectedItem = (String)CboInspectionType.getSelectedItem();
if (selectedItem.equals("Direct Repair Program"))
{
System.out.println("selectedItem : "+selectedItem);
try
{
this.remove(TabVIDRITabbedPane);
System.out.println("DRI Tab removed");
}
catch(NullPointerException ne)
{
System.out.println("Not able to remove DRI Tab");
try
{
this.remove(TabVIFLDTabbedPane);
System.out.println("FLD Tab removed");
}
catch(NullPointerException ne1)
{
System.out.println("Not able to remove FLD Tab");
}
}
finally
{
this.add(getTabVITabbedPane(), null);
TabVITabbedPane.setSelectedIndex(0);
}
}
else if (selectedItem.equals("Drive In"))
{
System.out.println("selectedItem : "+selectedItem);
try
{
this.remove(TabVITabbedPane);
System.out.println("DRP Tab removed");
}
catch(NullPointerException ne)
{
System.out.println("Not able to remove DRP Tab");
try
{
this.remove(TabVIFLDTabbedPane);
System.out.println("FLD Tab removed");
}
catch(NullPointerException ne1)
{
System.out.println("Not able to remove FLD Tab");
}
}
finally
{
this.add(getTabVIDRITabbedPane(), null);
TabVIDRITabbedPane.setSelectedIndex(0);
}
//getTabVIDRITabbedPane();
}
else if (selectedItem.equals("Field"))
{

System.out.println("selectedItem : "+selectedItem);
try
{
this.remove(TabVIDRITabbedPane);
System.out.println("DRI Tab removed");
}
catch(NullPointerException ne)
{
System.out.println("Not able to remove DRI Tab");
try
{
this.remove(TabVITabbedPane);
System.out.println("DRP Tab removed");
}
catch(NullPointerException ne1)
{
System.out.println("Not able to remove DRP Tab");
}
}
finally
{
System.out.println("Am I coming here");
SwingUtilities.updateComponentTreeUI(this);
this.add(getTabVIFLDTabbedPane(), null);
System.out.println("Am I crossing here");
TabVIFLDTabbedPane.setSelectedIndex(0);
CboFLDVICVehicleLocation.addActionListener(new ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt)
{
CboFLDVICVehicleLocation_ItemSelected(evt);
}
});

}
}
else if (selectedItem.equals("VIC"))
{
System.out.println("selectedItem : "+selectedItem);
}

}
When I added the logic for "Field" it is messig up the screens of "Direct Repair proram" and "Drive In".
Does anyone know what could be the reason for this problem ? Please let me know immediately. I am really in the tight schedule.
Thanks in advance,
Shanmugam.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are removing and adding panes based on the selection from a combobox a regular JPanel with CardLayout would be a better choice than a JTabbedPane. A JTabbedPane lets the user select a tab and move between them at will. A CardLayout in a JPanel lets you direct the user through a path one 'card' at a time.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!