- 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 separate Components in a Row or Column with Box in Java
To separate components in a row or column, use the createGlue() method. This creates an invisible "glue" component that separates components.
The following is an example to separate components in a row or column with Box −
Example
package my; import java.awt.BorderLayout; import javax.swing.Box; import javax.swing.BoxLayout; 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("Matches"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("CSK"); JButton button2 = new JButton("DC"); JButton button3 = new JButton("MI"); JButton button4 = new JButton("SRH"); JButton button5 = new JButton("RR"); JButton button6 = new JButton("KKR"); Box box = new Box(BoxLayout.X_AXIS); box.add(button1); box.add(button2); box.add(Box.createGlue()); box.add(button3); box.add(button4); box.add(Box.createGlue()); box.add(button5); box.add(button6); JScrollPane jScrollPane = new JScrollPane(); jScrollPane.setViewportView(box); frame.add(jScrollPane, BorderLayout.CENTER); frame.setSize(550, 250); frame.setVisible(true); } }
Output
- Related Articles
- How to create a Box to display components from left to right in Java
- How to Convert Vector / Single Row or Column to Matrix in Excel?
- How to add components with a Relative X Position in Java
- How to deal with reusable components in Selenium Java?
- How to remove the row names or column names from a matrix in R?
- How to enable row selection in a JTable with Java
- How to add components with a relative Y position in Java?\n
- How to highlight a row in a table with Java Swing?
- How to find repeated rows and display there count in a separate column with MySQL?
- Concatenate the column values with separate text in MySQL and display in a single column
- Why do we need to separate different components of a mixture? Explain with examples.
- Pull row with lowest number in a MySQL column?
- How can I separate Menu Items in a Menu with Java?
- Multiplying column with NULL row in MySQL?
- How to get row index or column index based on their names in R?

Advertisements