why isnt this scroll panel scrolling?

Discussion in 'Java' started by Justin, Nov 29, 2006.

  1. Justin

    Justin Guest

    heres my class file. All I am trying to do is get the scroll panel to
    have a scroll bar and the ability to scroll.

    Why does changing the size of the JScrollPane have no affect on it when
    I run the program? What do I have to do to gain scrolling
    capabilities?

    Thanks

    package orthopedicnotegenerator;

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.font.*;
    import java.text.Collator;
    import javax.swing.event.*;
    import java.util.Date;
    import java.text.DateFormat;

    class ExamKnee2 extends JDialog{

    final int WIDTH = 830;

    AccessConnection dataConnection = new AccessConnection();

    JPanel pane;
    JScrollPane scroller;

    public ExamKnee2() {

    setModal(true);
    Container pane = this.getContentPane();
    this.setAlwaysOnTop(true);
    pane.setLayout(new BorderLayout());
    //pane.setLayout(null);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setBounds(300,0,WIDTH,400);

    addWidgets();

    setVisible(true);
    validate();

    }

    public void addWidgets(){

    pane = new JPanel();
    pane.setLayout(new BorderLayout());

    JButton button = new JButton("Button 1 (PAGE_START)");
    pane.add(button, BorderLayout.PAGE_START);

    button = new JButton("Button 2 (CENTER)");
    button.setPreferredSize(new Dimension(200, 100));
    pane.add(button, BorderLayout.CENTER);

    button = new JButton("Button 3 (LINE_START)");
    pane.add(button, BorderLayout.LINE_START);

    button = new JButton("Long-Named Button 4 (PAGE_END)");
    pane.add(button, BorderLayout.PAGE_END);

    button = new JButton("5 (LINE_END)");
    pane.add(button, BorderLayout.LINE_END);

    scroller = new JScrollPane(pane);
    scroller.setSize(200,200);
    add(scroller, BorderLayout.CENTER);

    }

    public static void main(String args[]){
    ExamKnee2 examKnee = new ExamKnee2("Right", "123-45-6789", "2
    weeks");
    }
    }
    Justin, Nov 29, 2006
    #1
    1. Advertising

  2. Justin

    hiwa Guest

    Justin wrote:
    > heres my class file. All I am trying to do is get the scroll panel to
    > have a scroll bar and the ability to scroll.
    >
    > Why does changing the size of the JScrollPane have no affect on it when
    > I run the program? What do I have to do to gain scrolling
    > capabilities?
    >
    > Thanks
    >
    > package orthopedicnotegenerator;
    >
    > import java.awt.*;
    > import java.awt.event.*;
    > import javax.swing.*;
    > import java.awt.font.*;
    > import java.text.Collator;
    > import javax.swing.event.*;
    > import java.util.Date;
    > import java.text.DateFormat;
    >
    > class ExamKnee2 extends JDialog{
    >
    > final int WIDTH = 830;
    >
    > AccessConnection dataConnection = new AccessConnection();
    >
    > JPanel pane;
    > JScrollPane scroller;
    >
    > public ExamKnee2() {
    >
    > setModal(true);
    > Container pane = this.getContentPane();
    > this.setAlwaysOnTop(true);
    > pane.setLayout(new BorderLayout());
    > //pane.setLayout(null);
    >
    > setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    > setBounds(300,0,WIDTH,400);
    >
    > addWidgets();
    >
    > setVisible(true);
    > validate();
    >
    > }
    >
    > public void addWidgets(){
    >
    > pane = new JPanel();
    > pane.setLayout(new BorderLayout());
    >
    > JButton button = new JButton("Button 1 (PAGE_START)");
    > pane.add(button, BorderLayout.PAGE_START);
    >
    > button = new JButton("Button 2 (CENTER)");
    > button.setPreferredSize(new Dimension(200, 100));
    > pane.add(button, BorderLayout.CENTER);
    >
    > button = new JButton("Button 3 (LINE_START)");
    > pane.add(button, BorderLayout.LINE_START);
    >
    > button = new JButton("Long-Named Button 4 (PAGE_END)");
    > pane.add(button, BorderLayout.PAGE_END);
    >
    > button = new JButton("5 (LINE_END)");
    > pane.add(button, BorderLayout.LINE_END);
    >
    > scroller = new JScrollPane(pane);
    > scroller.setSize(200,200);
    > add(scroller, BorderLayout.CENTER);
    >
    > }
    >
    > public static void main(String args[]){
    > ExamKnee2 examKnee = new ExamKnee2("Right", "123-45-6789", "2
    > weeks");
    > }
    > }

    Your code won't compile, let alone run.
    If you need further help then you need to create a Short, Self
    Contained, Compilable and Executable, Example Program (SSCCE) that
    demonstrates the incorrect behaviour, because I can't guess exactly
    what you are doing based on the information provided.
    I think a panel only with five buttons need not to be scrolled.
    Why it should scroll? I don't understand.
    hiwa, Nov 29, 2006
    #2
    1. Advertising

  3. Justin wrote:
    > heres my class file. All I am trying to do is get the scroll panel to
    > have a scroll bar and the ability to scroll.
    >
    > Why does changing the size of the JScrollPane have no affect on it when
    > I run the program? What do I have to do to gain scrolling
    > capabilities?
    >
    > Thanks
    >
    > package orthopedicnotegenerator;
    >
    > import java.awt.*;
    > import java.awt.event.*;
    > import javax.swing.*;
    > import java.awt.font.*;
    > import java.text.Collator;
    > import javax.swing.event.*;
    > import java.util.Date;
    > import java.text.DateFormat;
    >
    > class ExamKnee2 extends JDialog{
    >
    > final int WIDTH = 830;
    >
    > AccessConnection dataConnection = new AccessConnection();

    Compile error: class AccessConnection not found
    >
    > JPanel pane;
    > JScrollPane scroller;
    >
    > public ExamKnee2() {
    >
    > setModal(true);
    > Container pane = this.getContentPane();
    > this.setAlwaysOnTop(true);

    Compile error: method setAlwaysOnTop(boolean) not found
    > pane.setLayout(new BorderLayout());
    > //pane.setLayout(null);
    >
    > setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    > setBounds(300,0,WIDTH,400);
    >
    > addWidgets();
    >
    > setVisible(true);
    > validate();
    >
    > }
    >
    > public void addWidgets(){
    >
    > pane = new JPanel();
    > pane.setLayout(new BorderLayout());
    >
    > JButton button = new JButton("Button 1 (PAGE_START)");
    > pane.add(button, BorderLayout.PAGE_START);
    >
    > button = new JButton("Button 2 (CENTER)");
    > button.setPreferredSize(new Dimension(200, 100));
    > pane.add(button, BorderLayout.CENTER);
    >
    > button = new JButton("Button 3 (LINE_START)");
    > pane.add(button, BorderLayout.LINE_START);
    >
    > button = new JButton("Long-Named Button 4 (PAGE_END)");
    > pane.add(button, BorderLayout.PAGE_END);
    >
    > button = new JButton("5 (LINE_END)");
    > pane.add(button, BorderLayout.LINE_END);
    >
    > scroller = new JScrollPane(pane);
    > scroller.setSize(200,200);
    > add(scroller, BorderLayout.CENTER);
    >
    > }
    >
    > public static void main(String args[]){
    > ExamKnee2 examKnee =
    > new ExamKnee2("Right", "123-45-6789", "2 weeks");

    Compile error: constructor ExamKnee(String,String,String) not found.
    > }
    > }
    >


    --
    Thomas
    Thomas Fritsch, Nov 30, 2006
    #3
  4. Justin wrote:

    > heres my class file. All I am trying to do is get the scroll panel to
    > have a scroll bar and the ability to scroll.


    > scroller = new JScrollPane(pane);

    The reason why you don't get scroll bars is described in the API docs of
    constructor JScrollPane(Component), which you should read now.
    How to get scrollbars is described in the docs of another JScrollPane
    constructor.

    --
    Thomas
    Thomas Fritsch, Nov 30, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon via DotNetMonster.com

    why isnt target="_blank" working????

    Jon via DotNetMonster.com, Apr 10, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    6,693
    Patrice
    Apr 10, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,848
    Smokey Grindel
    Dec 2, 2006
  3. Replies:
    1
    Views:
    242
  4. muelli75
    Replies:
    41
    Views:
    1,257
    cwdjrxyz
    Sep 1, 2010
  5. Dylan Parry
    Replies:
    1
    Views:
    391
Loading...

Share This Page