- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 display the vertical and horizontal scrollbars always even if it is not required
Use the following constants for the JScrollBar to display the vertical and horizontal scrollbars always even if it is not required −
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
The following is an example to display the vertical and horizontal scrollbars always even if it is not required −
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("Questions and Answers"); JButton button2 = new JButton("Videos"); JButton button3 = new JButton("Tools"); JButton button4 = new JButton("Tutorials"); JButton button5 = new JButton("Online Compiler"); JButton button6 = new JButton("Quiz"); 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); box.add(button6); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(box); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(550, 250); frame.setVisible(true); } }
Output
- Related Articles
- Vertical and Horizontal Scrollbars on Tkinter Widget
- Java Program to display both horizontal and vertical grid lines in a JTable
- When is plt.Show() required to show a plot and when is it not?
- CSS Central, Horizontal and Vertical Alignment
- Difference between Horizontal and Vertical Relationships
- How to set the horizontal and vertical radius of an Ellipse using FabricJS?
- Difference between vertical integration and horizontal integration
- Difference between Horizontal Equity and Vertical Equity
- FabricJS – How to scale an image equally on horizontal and vertical directions?
- How to independently set horizontal and vertical, major and minor gridlines of a plot?
- How to scale a Text object equally to horizontal and vertical direction using FabricJS?
- State whether the following statements are True or False:(a) The sum of three odd numbers is even.(b) The sum of two odd numbers and one even number is even.(c) The product of three odd numbers is odd.(d) If an even number is divided by 2, the quotient is always odd.(e) All prime numbers are odd.(f) Prime numbers do not have any factors.(g) Sum of two prime numbers is always even.(h) 2 is the only even prime number.(i) All even numbers are composite numbers.(j) The product of two even numbers is always even.
- Explain why, even clear, transparent and odourless water may not always be safe for drinking.
- How to hide scrollbars with CSS?
- Horizontal and Vertical Center Alignment with Flexbox in CSS3

Advertisements