Forum Stats

  • 3,839,864 Users
  • 2,262,546 Discussions
  • 7,901,086 Comments

Discussions

Adding ScrollBar to JOptionPane.showConfirmDialog

User_AYF65
User_AYF65 Member Posts: 135 Red Ribbon
edited Nov 4, 2015 8:01PM in New To Java

Hi,

I am trying to display scrolling facility in JOptionPane. I have 20 JTextFields but i can see only 16 of them. I have written the following code:

Object[] message={

  "Input value 1:",field1,

  "Input value 2:",field2,

  "Input value 3:",field3,

  "Input value 4:",field4,

  "Input value 5:",field5,

  "Input value 6:",field6,

  "Input value 7:",field7,

  "Input value 8:",field8,

  "Input value 9:",field9,

  "Input value 10:",field10,

  "Input value 11:",field11,

  "Input value 12:",field12,

  "Input value 13:",field13,

  "Input value 14:",field14,

  "Input value 15:",field15,

  "Input value 16:",field16,

  "Input value 17:",field17,

  "Input value 18:",field18,

  "Input value 19:",field19,

  "Input value 20:",field20,

  };

JScrollPane pane = new JScrollPane(message);

int option=JOptionPane.showConfirmDialog(null,pane,"Enter all values", JOptionPane.OK_CANCEL_OPTION);

I am getting following error message:

>javac AssQ1_2.java

AssQ1_2.java:57: error: incompatible types: Object[] cannot be converted to Comp

onent

JScrollPane pane = new JScrollPane(message);

                                   ^

Note: Some messages have been simplified; recompile with -Xdiags:verbose to get

full output

1 error

>

Somebody please guide me.

Zulfi.

Answers

  • User_AYF65
    User_AYF65 Member Posts: 135 Red Ribbon
    edited Nov 1, 2015 3:10AM

    Hi,

    I changed the code to:

    JScrollPane pane = new JScrollPane();

    pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

    Object[] message={

                      pane,

      "Input value 1:",field1,

      "Input value 2:",field2,

      "Input value 3:",field3,

      "Input value 4:",field4,

      "Input value 5:",field5,

      "Input value 6:",field6,

      "Input value 7:",field7,

      "Input value 8:",field8,

      "Input value 9:",field9,

      "Input value 10:",field10,

      "Input value 11:",field11,

      "Input value 12:",field12,

      "Input value 13:",field13,

      "Input value 14:",field14,

      "Input value 15:",field15,

      "Input value 16:",field16,

      "Input value 17:",field17,

      "Input value 18:",field18,

      "Input value 19:",field19,

      "Input value 20:",field20,

      };

    int option=JOptionPane.showConfirmDialog(null,message,"Enter all values", JOptionPane.OK_CANCEL_OPTION);

    Now i am not getting any error but no scroll bar visible. Somebody please guide me.

    Zulfi.

  • User_AYF65
    User_AYF65 Member Posts: 135 Red Ribbon
    edited Nov 1, 2015 3:18AM

    Hi,

    I changed the code to:

    JScrollBar scrollBar = new JScrollBar(JScrollBar.VERTICAL);

    Object[] message={

                      scrollBar,

      "Input value 1:",field1,

      "Input value 2:",field2,

      "Input value 3:",field3,

      "Input value 4:",field4,

      "Input value 5:",field5,

      "Input value 6:",field6,

      "Input value 7:",field7,

      "Input value 8:",field8,

      "Input value 9:",field9,

      "Input value 10:",field10,

      "Input value 11:",field11,

      "Input value 12:",field12,

      "Input value 13:",field13,

      "Input value 14:",field14,

      "Input value 15:",field15,

      "Input value 16:",field16,

      "Input value 17:",field17,

      "Input value 18:",field18,

      "Input value 19:",field19,

      "Input value 20:",field20,

      };

    int option=JOptionPane.showConfirmDialog(null,message,"Enter all values", JOptionPane.OK_CANCEL_OPTION);

    Its showing me something but its not a vertical scroll bar.

    Somebody please guide m.

    Zulfi.

  • User_AYF65
    User_AYF65 Member Posts: 135 Red Ribbon
    edited Nov 4, 2015 8:42AM

    Hi,

    Is this a limitation of Java or there exists a solution for it? Some body please guide me.

    Zulfi.

  • Unknown
    edited Nov 4, 2015 8:01PM

    Try the examples in the 'How to Use Scroll Panes' in the Java Tutorials

    https://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html

    That trail has working example code that will show you how scroll panes work.

This discussion has been closed.