Results 1 to 4 of 4
  1. #1
    Arthur is offline Member
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Question Problem with JScrollBar

    Java Code:
    import java.awt.Container;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JScrollBar;
    
    class ExamJScrollBar extends JFrame
    {
    private JLabel jlb1,jlb2;
    private JScrollBar jsb;
    private Container con;
        public ExamJScrollBar()
        {
            con=getContentPane();
            con.setLayout(null);
    
            jlb1=new JLabel("JSCROLLBAR");
            jlb1.setBounds(300, 40, 300, 20);
            con.add(jlb1);
    
            jlb2=new JLabel("Contructor");
            jlb2.setBounds(20, 700, 100, 20);
            con.add(jlb2);
    
            jsb=new JScrollBar();
            jsb.setBounds(780,0,20,580);
            con.add(jsb);
        }
        public static void main(String[] args)
        {
            ExamJScrollBar ex = new ExamJScrollBar();
            ex.setVisible(true);
            ex.setBounds(0,0,800,600);
            ex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    }
    When I drag-down ScrollBar, I don't see "Contructor" with Location (20,700). :confused::confused::confused:
    Please! Help me! :)

  2. #2
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default

    The location of the label "Constructor" is beyond the frame borders (y coordinate). the y-coordinate of the border of the frame is 600 while you are trying to add a label at the y-coordinate 700.

    Try changing the
    jlb2.setBounds(20, 700, 100, 20);

    to

    jlb2.setBounds(20, 550, 100, 20);

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Better yet learn how to use Layout Managers so you don't have this type of problem. Read the section from the Swing tutorial on Layout Managers.

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Another good point. Swing will automatically move things around in a way that makes sense as the window size changes, if you use a layout manager correctly.

Similar Threads

  1. A problem with JScrollBar and the Jbutton
    By cowboy in forum New To Java
    Replies: 5
    Last Post: 12-19-2009, 10:17 PM
  2. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 07:12 AM
  3. JScrollBar
    By solomon_13000 in forum AWT / Swing
    Replies: 1
    Last Post: 07-01-2009, 08:46 AM
  4. problem with jscrollbar in my applet
    By leonard in forum Java Applets
    Replies: 1
    Last Post: 08-04-2007, 12:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •