You can use the following coding for the top-level container :
Code:
package components;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TopLevelDemo {
private static void createAndShowGUI() {
JFrame frame = new JFrame("TopLevelTrial");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar greenMenuBar = new JMenuBar();
greenMenuBar.setOpaque(true);
greenMenuBar.setBackground(new Color(204, 157, 142));
greenMenuBar.setPreferredSize(new Dimension(140, 28));
JLabel yellowLabel = new JLabel();
yellowLabel.setOpaque(true);
yellowLabel.setBackground(new Color(148, 103, 211));
yellowLabel.setPreferredSize(new Dimension(107, 150));
frame.setJMenuBar(greenMenuBar);
frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Bookmarks