

- 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 vertical and horizontal scrollbars always even if it is not required
<p>Use the following constants for the JScrollBar to display the vertical and horizontal scrollbars always even if it is not required −</p><pre class="result notranslate">scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);</pre><p>The following is an example to display the vertical and horizontal scrollbars always even if it is not required −</p><h2>Example</h2><pre class="prettyprint notranslate">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); } }</pre><h2>Output</h2><p><img src="https://www.tutorialspoint.com/assets/questions/media/23982/demo_tut.jpg" class="fr-fic fr-dib" style="width: 504px; height: 227.221px;" width="504" height="227.221"></p>
- Related Questions & Answers
- Vertical and Horizontal Scrollbars on Tkinter Widget
- When is plt.Show() required to show a plot and when is it not?
- CSS Central, Horizontal and Vertical Alignment
- Java Program to display both horizontal and vertical grid lines in a JTable
- Difference between vertical integration and horizontal integration
- How to set the horizontal and vertical radius of an Ellipse using FabricJS?
- Create JList and always display the scroll bar in Java?
- Write the difference between horizontal and vertical analysis of financial statements.
- Horizontal and Vertical Center Alignment with Flexbox in CSS3
- Is it always true that Big/Branded Hospitals always grabbing unnecessary money from patients?
- Check if table exists in MySQL and display the warning if it exists?
- How to independently set horizontal and vertical, major and minor gridlines of a plot?
- Python a += b is not always a = a + b
- Check horizontal and vertical symmetry in binary matrix in C++
- MongoDB query to add timestamp only if it is not present
Advertisements