- 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
Display multiple components in an Internal Frame in Java
At first, set an Internal Frame in the JDesktopPane −
JDesktopPane desktopPane = new JDesktopPane(); JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true); desktopPane.add(intFrame);
Now, set the bounds of the Internal Frame −
intFrame.setBounds(50, 90, 200, 250);
Create two components −
JLabel label = new JLabel(intFrame.getTitle(), JLabel.CENTER); JButton button = new JButton("Demo Button");
Add the two components to the Internal Frame −
intFrame.add(label, BorderLayout.CENTER); intFrame.add(button, BorderLayout.WEST);
The following is an example to display multiple components in an internal frame −
package my; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(final String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JDesktopPane desktopPane = new JDesktopPane(); JInternalFrame intFrame = new JInternalFrame("Our Frame", true, true, true, true); desktopPane.add(intFrame); intFrame.setBounds(50, 90, 200, 250); JLabel label = new JLabel(intFrame.getTitle(), JLabel.CENTER); JButton button = new JButton("Demo Button"); intFrame.add(label, BorderLayout.CENTER); intFrame.add(button, BorderLayout.WEST); intFrame.setVisible(true); frame.add(desktopPane, BorderLayout.CENTER); frame.setSize(600, 500); frame.setVisible(true); } }
Output
The following is the result after clicking the maximize button on the above displayed Internal Frame −
Advertisements