• Post Reply Bookmark Topic Watch Topic
  • New Topic

Vertical ScrollBar of a JScrollPane not functioning??

 
burre kv
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following components:
1) JSplitPane
2) JTree
3) JTabbedPane
To the LEFT of the JSplitPane is the JTree.
To the RIGHT of the JSplitPane is the JTabbedPane.
In one of the Tabs of the JTabbedPane I have several JTextFields and JLabels aligned vertically.
MY PROBLEM IS :
I am unable to display or make the vertical scrollbar work of a JScrollPane that is added to the tab containing the JTextFields and Jlabels .It's just not working.
MY CODE IS AS FOLLOWS SMALL CODE)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class TabScroll extends JFrame
{
private JSplitPane splitPane;
private JLabel aLabel1[];
private JTextField aTextField1[];
private JPanel aPanel1;
private JPanel comm_ports;
private JTabbedPane tabbedPane;
private JTree tree;
private JScrollPane treeView;

String Str[] = {"LABEL-1","LABEL-2","LABEL-3",
"LABEL-4","LABEL-5","LABEL-6","LABEL-7",
"LABEL-8","LABEL-9"};
int al=10,y_al=10;
private JPanel mainPanel;
TabScroll()
{
mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());

aPanel1 = new JPanel();
aPanel1.setLayout(null);
aLabel1 = new JLabel[Str.length];
aTextField1 = new JTextField[Str.length];
tabbedPane = new JTabbedPane();
tabbedPane.addTab(" ABC " ,null,new JScrollPane(aPanel1,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),"ABC Table");
comm_ports = new JPanel();
tabbedPane.addTab(" COMM",null,comm_ports,"Input_port");

for(int i = 0; i < Str.length; i++)
{
aLabel1[i] = new JLabel(Str[i]);
aLabel1[i].setBounds( 10, al, 170, 20 );
aPanel1.add(aLabel1[i]);
aTextField1[i] = new JTextField(20);
aTextField1[i].setBounds(40,y_al,120,20);
aPanel1.add(aTextField1[i]);
al=al+60;
y_al=y_al+60;
}

mainPanel.add(tabbedPane);
tree = new JTree();
treeView = new JScrollPane(tree);
splitPane = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(treeView);
splitPane.setRightComponent(mainPanel);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(190);
splitPane.setPreferredSize
(new Dimension(785, 540));
getContentPane().add(splitPane);
setSize(600,400);
setVisible(true);
setTitle("ScrollPane Demo");
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[])
{
new TabScroll();
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!