- 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 display a large component within a smaller display area in Java?
To display a large component in a smaller display area, use JScrollPane, so that it’s easier for user to scroll through the component. The following is an example to display large component within a smaller display area 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("One"); JButton button2 = new JButton("Two"); JButton button3 = new JButton("Three"); JButton button4 = new JButton("Four"); JButton button5 = new JButton("Five"); JButton button6 = new JButton("Six"); Box box = Box.createVerticalBox(); box.add(button1); box.add(button2); box.add(button3); box.add(button4); box.add(button5); box.add(button6); box.setPreferredSize(new Dimension(900,900)); JScrollPane jScrollPane = new JScrollPane(); jScrollPane.setViewportView(box); frame.add(jScrollPane, BorderLayout.CENTER); frame.setSize(550, 250); frame.setVisible(true); } }
This will produce the following output −
- Related Articles
- How to display a JRadioButtonMenuItem in Java?\n
- How do we display a text area in HTML?
- Display a percentage in Java
- How to display the items in a JComboBox in Java
- How can we get the values of a JProgressBar Component and display in Console?
- Display a currency value in Java
- Display text inside an element in a smaller font size with Bootstrap
- Java Program to display a webpage in JEditorPane
- How to display the first element in a JComboBox in Java
- How to display a value when select a JList item in Java?
- How to display a JFrame to the center of a screen in Java?
- How to hide and display JCombobox with a JCheckBox in Java?
- How to display horizontal grid lines in a JTable with Java?
- How to display vertical grid lines in a table with Java?
- How to display a fieldset in HTML?

Advertisements