Hi,
I m trying to scroll the JLabel by adding JLabel to Jscrollpane,I can see the scrollbar,but I can't scroll as well as I found JLabel's are misplaced.Can anyone please help me to solve this.
The following is the code,
class outerWindow extends JFrame implements KeyListener,ActionListener
{
Container c = null;
JPanel pane;
public outerWindow()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c = getContentPane();
pane = new JPanel(null);
pane.setLayout(null);
pane.setBounds(0,0,750,550);
pane.setBackground(Color.gray);
JLabel lab_test = new JLabel("Test");
lab_test.setBounds(0,10,210,1000);
lab_test.setBackground(Color.yellow);
lab_test.setForeground(Color.black);
lab_test.setOpaque(true);
lab_test.setFont(new java.awt.Font("Arial",1,30));
lab_test.setHorizontalAlignment(JTextField.CENTER);
lab_test.setFocusable(false);
lab_test.setVisible(true);
JLabel[] lab = new JLabel[50];
for(int i=0;i<50;i++)
{
lab[i] = new JLabel("new");
lab[i].setBounds(70*(i%3),70*(i/3),70,70);
lab[i].setOpaque(true);
lab[i].setBackground(Color.green);
lab[i].setFont(new java.awt.Font("Arial",1,30));
lab[i].setVerticalAlignment(JTextField.BOTTOM);
JLabel labIn = new JLabel("Boost");
labIn.setBounds(0,0,65,20);
lab[i].add(labIn);
lab_test.add(lab[i]);
}
JScrollPane scrPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrPane.setBounds(50,10,230,300);
//scrPane .getViewport().add( lab_test);
scrPane.add( lab_test);
pane.add( scrPane , BorderLayout.CENTER );
c.add(pane);
c.setBackground(Color.white);
c.addKeyListener(this);
setSize(800,600);
this.setVisible(true);
c.requestFocus();
}
--Thanks--