Concept explainers
Explanation of Solution
Purpose of the given code:
The purpose of the give code snippet is for creating a list and adding it to the scroll pane.
Given code:
//create a JList and add it to a scroll pane.
//assume that array already exists.
JList list=new Jlist(array);
JScrollPane scrollPane=new JScrollPane();
scrollPane.add(list);
Error in the above code:
- To add the list created into the scroll pane it required to add the list that is to be passed as the argument by creating a “JScrollPane” object and the required component into it.
Corrected code:
//create a JList and add it to a scroll pane.
//assume that array already exists.
JList list=new Jlist(array);
JScrollPane scrollPane=new JScrollPane(list);
Explanation:
- An object for the “JScrollPane” is create and the component is added as argument
Adding scroll bar to the list:
Normally, a list contains more space to display many elements. Sometimes a list contains too many elements to be displayed at once, so most GUI applications use scroll bar on list components which contains a large number of elements...
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education