| | |
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:
Solved Threads: 0
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,
--Thanks--
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,
java Syntax (Toggle Plain Text)
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--
Last edited by WolfPack; Mar 21st, 2008 at 11:07 am. Reason: Added [CODE=JAVA][/CODE] TAgs. Use them whem you post code.
![]() |
Similar Threads
- I'm having problems (Java)
- Source Code that don't work? (Java)
- Hey check out my prog. It has an error can u find it? (Java)
Other Threads in the Java Forum
- Previous Thread: help me...
- Next Thread: How to disable windows key in java?
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api append apple applet application arguments array arrays automation bi binary bluetooth businessintelligence busy_handler(null) chat class classes client code component database draw eclipse encryption equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop main map method methods mobile netbeans newbie number open-source oracle oriented panel print problem program programming project qt recursion reference replaysolutions repositories return robot scanner screen scrollbar se server set singleton size sms socket sort sql string swing test threads time tree utility windows xor





