Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.4K Development
- 17 Developer Projects
- 139 Programming Languages
- 293.1K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 161 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 475 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Adding ScrollBar to JOptionPane.showConfirmDialog

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
-
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.
-
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.
-
Hi,
Is this a limitation of Java or there exists a solution for it? Some body please guide me.
Zulfi.
-
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.