- 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
Java Program to place component in bottom-right corner with BorderLayout
We have created a button component here, which will places in bottom-right corner −
JButton button = new JButton("This is Demo Text!"); button.setBackground(Color.blue); button.setForeground(Color.white);
Create panels now to arrange the above created button component in the bottom right −
JPanel bottomPanel = new JPanel(new BorderLayout()); bottomPanel.add(button, BorderLayout.LINE_END); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(bottomPanel, BorderLayout.PAGE_END);
The following is an example to place a component in bottom-right corner with BorderLayout −
Example
package my; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo { public static void main(String[] args) { JButton button = new JButton("This is Demo Text!"); button.setBackground(Color.blue); button.setForeground(Color.white); JPanel bottomPanel = new JPanel(new BorderLayout()); bottomPanel.add(button, BorderLayout.LINE_END); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(bottomPanel, BorderLayout.PAGE_END); // mainPanel.setPreferredSize(new Dimension(550, 400)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(mainPanel); frame.setSize(550, 400); frame.setLocationRelativeTo(null); frame.setVisible(true); } }
Output
- Related Articles
- Set bottom-right corner border with CSS
- Program to find minimum number of cells it will take to reach bottom right corner in Python
- How to get an element to stick to the bottom-right corner in Tkinter?
- Set bottom-left corner border with CSS
- Set a component and place it next to the previously added component with GridBagLayout in Java
- Program to combine BorderLayout, GridLayout and FlowLayout in Java Swing?
- Set top-right corner border with CSS
- Java program to insert a component into a JTextPane component
- Java Program to set the content of the JLabel to be right-justified and bottom-aligned
- Can we combine GridLayout and BorderLayout in Java?
- How to show (0,0) on matplotlib graph at the bottom left corner?
- How to disallow resizing component with GridBagLayout in Java
- Java Program to insert styled text in a JTextPane Component
- How to position text to bottom right on an image with CSS
- How to set the shape of the border of the top-right corner with JavaScript?

Advertisements