- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 set Row Header View for JScrollPane in Java?
Set Row Header View using the setRowHeaderView() method. Let us first create a KScrollPane and set a list −
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);
Now, set the row header view −
scrollPane.setRowHeaderView(new JLabel("All List Items "));
The following is an example to set row header view for JScrollPane in Java −
Example
package my; import java.awt.BorderLayout; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JLabel; 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 ArrayListlt;>(10); for (int index = 0; index lt; 20; index++) { myList.add("List Item " + index); } final JListlt;String> list = new JListlt;String>(myList.toArray(new String[myList.size()])); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(list); scrollPane.setRowHeaderView(new JLabel("All List Items ")); list.setLayoutOrientation(JList.VERTICAL); 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 Articles
- How to set horizontal header for a table?
- How to Set opacity for View in Android?
- How to Set opacity for View in iOS?
- How to set default value for empty row in MySQL?
- How do we specify whether a header cell is a header for a column, row, or group of columns or rows in HTML?
- How to set the Row Height of a JTree with Java?
- How to set JAVA_HOME for Java in Windows?
- How to set JAVA_HOME for Java in Linux?
- How to set FlowLayout for JFrame in Java?
- How to set style for JTextPane in Java?
- How to add header item for Listview in Android?
- How to set Web view Render Priority in android?
- How to set Adapter to Auto Complete Text view?
- How to set tooltip text for JCheckBox in Java?
- How to set default button for JFrame in Java?

Advertisements