
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to display the JList items from top to bottom and left to right in Java?
For this, set the layout orientation to the following −
setLayoutOrientation(JList.VERTICAL_WRAP);
The following is an example to display the JList items from top to bottom and left to right −
Example
package my; import java.awt.BorderLayout; import java.util.ArrayList ; import java.util.List; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; public class SwingDemo { public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); List<String> myList = new ArrayList<>(10); for (int index = 0; index < 20; index++) { myList.add("List Item " + index); } final JList<String> list = new JList<String>(myList.toArray(new String[myList.size()])); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(list); list.setLayoutOrientation(JList.VERTICAL_WRAP); panel.add(scrollPane); JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setSize(500, 250); frame.setLocationRelativeTo(null); frame.setVisible(true); } }
Output
- Related Questions & Answers
- Maximum points from top left of matrix to bottom right and return back in C++
- Set the left, right, top and bottom padding of an element
- Print all palindromic paths from top left to bottom right in a matrix in C++
- How to add a straight line to a plot in R starting from bottom left and ending at top right?
- Set the flex items vertically from bottom to top with CSS
- How to create a Box to display components from left to right in Java
- Print all possible paths from top left to bottom right of a mXn matrix in C++
- Count all possible paths from top left to bottom right of a mXn matrix in C++
- Program to count number of walls required to partition top-left and bottom-right cells in Python
- Set the flex items horizontally from right to left with CSS
- Program to find number of ways we can reach from top left point to bottom right point in Python
- Print all paths from top left to bottom right in a matrix with four moves allowed in C++
- How to display text Right-to-Left Using HTML?
- How to display only a left and bottom box border in Matplotlib?
- How to handle right-to-left and left-to-right swipe gestures on Android?
Advertisements