
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 −
Advertisements