How to make scroll the JLabel in java?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2008
Posts: 53
Reputation: ramjeev is an unknown quantity at this point 
Solved Threads: 0
ramjeev ramjeev is offline Offline
Junior Poster in Training

How to make scroll the JLabel in java?

 
0
  #1
Mar 21st, 2008
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,


  1. class outerWindow extends JFrame implements KeyListener,ActionListener
  2. {
  3. Container c = null;
  4. JPanel pane;
  5.  
  6. public outerWindow()
  7. {
  8.  
  9. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  10. c = getContentPane();
  11. pane = new JPanel(null);
  12. pane.setLayout(null);
  13. pane.setBounds(0,0,750,550);
  14. pane.setBackground(Color.gray);
  15.  
  16.  
  17. JLabel lab_test = new JLabel("Test");
  18. lab_test.setBounds(0,10,210,1000);
  19. lab_test.setBackground(Color.yellow);
  20. lab_test.setForeground(Color.black);
  21. lab_test.setOpaque(true);
  22. lab_test.setFont(new java.awt.Font("Arial",1,30));
  23. lab_test.setHorizontalAlignment(JTextField.CENTER);
  24. lab_test.setFocusable(false);
  25. lab_test.setVisible(true);
  26.  
  27. JLabel[] lab = new JLabel[50];
  28.  
  29. for(int i=0;i<50;i++)
  30. {
  31. lab[i] = new JLabel("new");
  32. lab[i].setBounds(70*(i%3),70*(i/3),70,70);
  33. lab[i].setOpaque(true);
  34. lab[i].setBackground(Color.green);
  35. lab[i].setFont(new java.awt.Font("Arial",1,30));
  36. lab[i].setVerticalAlignment(JTextField.BOTTOM);
  37.  
  38. JLabel labIn = new JLabel("Boost");
  39. labIn.setBounds(0,0,65,20);
  40. lab[i].add(labIn);
  41.  
  42. lab_test.add(lab[i]);
  43. }
  44.  
  45.  
  46. JScrollPane scrPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
  47. JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  48. scrPane.setBounds(50,10,230,300);
  49. //scrPane .getViewport().add( lab_test);
  50. scrPane.add( lab_test);
  51. pane.add( scrPane , BorderLayout.CENTER );
  52.  
  53. c.add(pane);
  54. c.setBackground(Color.white);
  55. c.addKeyListener(this);
  56.  
  57. setSize(800,600);
  58. this.setVisible(true);
  59. c.requestFocus();
  60. }

--Thanks--
Last edited by WolfPack; Mar 21st, 2008 at 11:07 am. Reason: Added [CODE=JAVA][/CODE] TAgs. Use them whem you post code.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 786
Reputation: Phaelax is on a distinguished road 
Solved Threads: 39
Phaelax Phaelax is offline Offline
Master Poster

Re: How to make scroll the JLabel in java?

 
0
  #2
Mar 21st, 2008
You probably need to add the labels to a jpanel then add that panel to the scroll pane.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 53
Reputation: ramjeev is an unknown quantity at this point 
Solved Threads: 0
ramjeev ramjeev is offline Offline
Junior Poster in Training

Re: How to make scroll the JLabel in java?

 
0
  #3
Mar 28th, 2008
Thanks buddy,

Its cleared in some way now.I m using JscrollBar seperately and JPanel seperately fix both closely so that its seems that its own scroll.I m loaded n number of labels in that panel.When I scroll, i m refreshing the labels with new text,so that its seems to be scroll.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC