

- 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
Display only the horizontal scrollbar in Java
To display only the horizontal scrollbar, use the VERTICAL_SCROLLBAR_NEVER constant, which eventually displays only the horizontal scrollbar.
The following is an example to display only the horizontal scrollbar in Java −
Example
package my; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Online Compiler"); JButton button2 = new JButton("Quiz"); JButton button3 = new JButton("Questions and Answers"); JButton button4 = new JButton("Videos"); JButton button5 = new JButton("Tools"); Box box = Box.createVerticalBox(); box.setPreferredSize(new Dimension(900,900)); box.add(button1); box.add(button2); box.add(button3); box.add(button4); box.add(button5); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(box); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(550, 250); frame.setVisible(true); } }
The output is as follows −
- Related Questions & Answers
- How to disable only the horizontal scrollbar in Java?
- Disable only the vertical scrollbar in Java
- Java Program to display only horizontal grid lines in a JTable
- How to get a horizontal scrollbar in Tkinter?
- How to display horizontal grid lines in a JTable with Java?
- Querying only the field name and display only the id in MongoDB?
- How to add ScrollBar to JList in Java?
- Plot the dataset to display Horizontal Trend – Python Pandas
- Java Program to display both horizontal and vertical grid lines in a JTable
- How to display only the current year in JavaScript?
- Java Program to display only vertical grid lines in a JTable
- Tkinter scrollbar for frame
- Display only the default values set for columns in MySQL
- Only display specified values inside the IN clause with MySQL?
- Display only the duplicate column names appearing atleast thrice in MySQL
Advertisements