Home Answers Viewqa Framework Container - add()

 
 


shraddha
Container - add()
1 Answer(s)      4 years and 7 months ago
Posted in : Framework

View Answers

October 23, 2008 at 3:15 PM


Hi,



I am sending simple code.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ContainerDemo {

private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("using component");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create the menu bar.
JMenuBar menuBar = new JMenuBar();
menuBar.setOpaque(true);
menuBar.setBackground(new Color(154, 165, 127));
menuBar.setPreferredSize(new Dimension(200, 20));
//Create a yellow label to put in the content pane.
JLabel yellowLabel = new JLabel();
yellowLabel.setOpaque(true);
yellowLabel.setBackground(new Color(248, 213, 131));
yellowLabel.setPreferredSize(new Dimension(200, 180));

//Set the menu bar and add the label to the content pane.
frame.setJMenuBar(greenMenuBar);
frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);

frame.setSize(300,200);
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
---------------------------
if you have any problem then send me code in detail.


---------------------------------

Read for more information.

http://www.roseindia.net/java/example/java/swing/

Thanks.









Related Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.