• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to display JScrollPane when added to a JTabbedPane(Plz SEE THIS)  RSS feed

 
sharath kv
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir/Madam
My GUI is as follows:
-----------------------------------------
JMenuBar
-----------------------------------------
| | |
| JTree | JTabbedPane |
| | |
| | JLabel..............|
| | JTextField..........|
| | |
| | |
| | |
| | |
| | |
------------------------------------------
Under one TabPane are several JLabels with JTextFields in 2 rows as follows:

JLabel1 JLabel2.................JLabelN
JTextField1 JTextField2.............JTextFieldN
MY PROBLEM IS :
* I am unable to add a JScrollPane to the JTabbedPane that contains the Panel with the JTextFields and JLabels.
* I am unable to view the remaining JLabels and JTextFields that are out of the viewing area of the JTabbedPane.
I need to add a HORIZONTAL JScrollPane to the JTabbedPane with the JTextFields & JLabels to view all the fields.
MY SOURCE CODE IS AS FOLLOWS:
public class PaneDemo3 extends JFrame
{
private JSplitPane splitPane;
private JPanel Nes; // For the JTabbedPane

private JTree tree; // For the JTree
private JTabbedPane tabbedPane;
// For the JScrollPane for the JTree.
private JScrollPane treeView;

private JPanel mainPanel;
String nesStr[] = {"ID","TYPE","SELECTION_NAME","GROUP_ID","MANAGED","SE_PORT",
"LAST_COMM_TIME","LAST_CONFIG_TIME","LAST_AUDIT_TIME","LAST_ALARM_SYNC_TIME",
"AVAILABLE","SRVC_AVAILABLE","ADDRESS","COMM_PORT","FDN","PARENT_FDN","SEVERITY",
"STATE","PROTOCOL","TIMEOUT","SEC_USER","SEC_PSWD","REMARKS","FLASH","EOC","DELIMITER",
"SCRAMBLE","CONNECTION_IDLE_TIMEOUT","SID","ALIGNED","INTERFACE"};
private JLabel nesLabel[]; // Array of JLabels
private JTextField nesTextField[];

String get_clli_val;
public PaneDemo3(JScrollPane treeView,final JTree sqlj_tree)
{
mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());

// Creating a JMenuBar and adding it to the
// mainPanel. Adding mainPanel to the Container

JMenuBar mainMenuBar = new JMenuBar();
setJMenuBar(mainMenuBar);
MenuExample s = new MenuExample();
JMenuBar guiMenu = s.MenuExample();
mainPanel.add(mainMenuBar.add(guiMenu), BorderLayout.NORTH);
getContentPane().add(mainPanel);
sqlj_tree.expandRow(0);
sqlj_tree.setShowsRootHandles(true);
tabbedPane = new JTabbedPane();
// creating JLabels with the JTextFields and
// adding these to a JPanel called Nes.
nesLabel = new JLabel[nesStr.length];
nesTextField = new JTextField[nesStr.length];
Nes = new JPanel();
Nes.setLayout(null);
int al=10; int y_al=10;
for(int i=0;i<nesStr.length;i++)
{
nesLabel[i] = new JLabel(nesStr[i]);
nesLabel[i].setBounds( al, 15, 170, 20 );
Nes.add(nesLabel[i]);
nesTextField[i] = new JTextField();
nesTextField[i].setBounds(y_al,35,120,20);
Nes.add(nesTextField[i]);
al=al+140;
y_al = y_al+140;
}

// creating a JTabbedPane and adding JPanel Nes
// to the JTabbedPane
tabbedPane.addTab(" NES " ,null,Nes,"NES Table");

tabbedPane.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
int index = tabbedPane.getSelectedIndex();
String title = tabbedPane.getTitleAt(index);
switch(index)
{
case 0: tree_selection_event(sqlj_tree,tabbedPane);
break;
}
}
}
);

for(int j=0;j<nesStr.length;j++)
{
nesTextField[j].setEditable(false);
}
// Creating a JScrollPane and adding the above
// created tabbedPane.
JScrollPane sp = new JScrollPane(tabbedPane);

// creating a JSpliPane and adding to the
// left is the JTree and to the right is the
// JScrollpane with the JTabbedPane(above).
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(treeView);
splitPane.setRightComponent(sp);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(190); // Used to size the divider location
splitPane.setPreferredSize(new Dimension(785, 540));
//adding the JSplitPane to the mainPanel(above)
mainPanel.add(splitPane);
//Adding mainPanel to the Container.
getContentPane().add(mainPanel);

pack();
setVisible(true);
setSize(new Dimension(800,580));
setTitle("PaneDemo2");
setDefaultCloseOperation(EXIT_ON_CLOSE);
} // end of constructor
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose you want to have the JScrollPane on the specific tabs of the JTabbedPane as a scrollable JTabbedPane doesn't make sense to me - you wouldn't see the tabs all the time.
replace
tabbedPane.addTab(" NES " ,null,Nes,"NES Table");
with
tabbedPane.addTab(" NES " ,null, new JScrollPane(Nes),"NES Table");
chantal
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!