The Artima Developer Community
Sponsored Link

Java Answers Forum
menus appear behind Container

3 replies on 1 page. Most recent reply: Mar 12, 2002 6:53 PM by Bill Venners

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
William Bogdanowich

Posts: 5
Nickname: billbogs
Registered: Mar, 2002

menus appear behind Container Posted: Mar 12, 2002 12:27 PM
Reply to this message Reply
Advertisement
I have a Jframe with a menu and some submenus
Menu
Submenu1
Submenu2
Submenu3

I then create 3 containers in the frame using GridBagLayout to position them
Container one is JPanel
Container one is JTextAreal
Container one is Jpanel

When I make my menu selection the part of the Submenu that goes through the first Jpanel masked by the Jpanel.

How do I get the menu selections to be displayed on top of the frames and not behind them

code beneath








 
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
public class MainWindow extends JFrame implements WindowListener, ActionListener {
 
   private JMenuBar menuBar = new JMenuBar();      // Window menu bar
String newline = "\n";
   String[] fileItems = new String[] { "New", "Save", "Print", "Exit" };
   String[] unitItems = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
   char[] fileShortcuts = { 'N','S','P','X' };
 
   int startTimeMinute = 0;
   int startTimeSecond = 0;
   int endTimeMinute = 50;
   int endTimeSecond = 9;
 
   private JPanel startDisplay;
   private JTextArea dataIn;                           //text panel
   private Panel controlPanel;                        //Button control panel
   private Button openButton, closeButton, markButton;
 
   public MainWindow() {
      super("PTC DATA REDUCTION");
      addWindowListener(this);
 
      /*****  Select Layout Manager Interface  *****/
      Container contentPane = getContentPane();
      GridBagLayout gridbag = new GridBagLayout();
      GridBagConstraints c = new GridBagConstraints();
      contentPane.setLayout(gridbag);
 
      /*****  Sets up main screen data areas  *****/
      try {
 
         // controlls the message data area on the main display
         startDisplay = new JPanel ();
         startDisplay.setBackground(Color.yellow);
         startDisplay.setLayout(new FlowLayout(FlowLayout.LEFT));
         Label messageLabel = new Label(" ");
         Font fontHev9 = new Font("Helvetica", Font.PLAIN, 12);
         startDisplay.setFont(fontHev9);
         startDisplay.add(messageLabel, "Left");
 
         addComponent (contentPane, startDisplay, 0, 0,
                       GridBagConstraints.REMAINDER, 1,
                       GridBagConstraints.HORIZONTAL,
                       GridBagConstraints.NORTHWEST,
                       1.0, 0.0);
 
         // controlls the data text area on the main display
 
         dataIn = new JTextArea(20,20);
         dataIn.setBackground(Color.green);
 
         addComponent (contentPane, dataIn, 0,
                       GridBagConstraints.RELATIVE,
                       GridBagConstraints.REMAINDER, 1,
                       GridBagConstraints.BOTH,
                       GridBagConstraints.EAST, 1.0, 1.0);
 
         // controlls the Portfolio Buttons area on the main display
 
         controlPanel = new Panel();
         controlPanel.setLayout (new FlowLayout());
         controlPanel.setBackground(Color.pink);
 
         openButton = new Button("Open Port");
         openButton.addActionListener(this);
         controlPanel.add(openButton);
         openButton.setEnabled(false);
 
         closeButton = new Button("Close Port");
         closeButton.addActionListener(this);
         controlPanel.add(closeButton);
         closeButton.setEnabled(false);
 
         markButton = new Button("Mark");
         markButton.addActionListener(this);
         controlPanel.add(markButton);
         markButton.setEnabled(false);
 
         addComponent (contentPane, controlPanel, 0,
                       GridBagConstraints.RELATIVE,
                       GridBagConstraints.REMAINDER, 1,
                       GridBagConstraints.HORIZONTAL,
                       GridBagConstraints.SOUTHWEST, 1.0, 0.0);
      }
 
      // Catch AWT exception
      catch (Exception e) {
         System.out.println("MainWindow: problem with AWT: ");
         e.printStackTrace();
      }
 
     updateDisplay();
 
      /*
       * Menu begin
       */
      setJMenuBar(menuBar);
 
      /*
       * Makes File menu and Submenu
       */
      JMenu fileMenu = new JMenu("File");
      JMenu startMenu = new JMenu("Start Time");
      JMenu startMinSubMenu = new JMenu("Minutes");
      JMenu startSecSubMenu = new JMenu("Seconds");
      JMenu endMenu = new JMenu("End Time");
      JMenu endMinSubMenu = new JMenu("Minutes");
      JMenu endSecSubMenu = new JMenu("Seconds");
      JMenu helpMenu = new JMenu("Help");
 
      /*
       * Assemble the File menus with keyboard accelerators
       */
      for (int i=0; i < fileItems.length; i++) {
         JMenuItem item = new JMenuItem(fileItems[i], fileShortcuts[i]);
         item.setAccelerator(KeyStroke.getKeyStroke(fileShortcuts[i],
                             java.awt.Event.CTRL_MASK, false));
         item.addActionListener(this);
         fileMenu.add(item);
      }
 
      /*
       * Assemble the submenus of the Start Time Menu for minutes.
       * Register a listener for the radio buttons.
       */
      ButtonGroup startMinTypes = new ButtonGroup();
      JMenu start00Min = new JMenu("00");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item00Unit = new JRadioButtonMenuItem(unitItems[x]);
         item00Unit.addActionListener(this);
         start00Min.add(item00Unit);
         startMinTypes.add(item00Unit);
         item00Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeMinute = Integer.parseInt(event.getActionCommand());
            updateDisplay();
            }
         });
      }
 
      JMenu start10Min = new JMenu("10");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item10Unit = new JRadioButtonMenuItem(unitItems[x]);
         item10Unit.addActionListener(this);
         start10Min.add(item10Unit);
         startMinTypes.add(item10Unit);
         item10Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeMinute = Integer.parseInt(event.getActionCommand()) + 10;
            updateDisplay();
            }
         });
      }
 
      JMenu start20Min = new JMenu("20");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item20Unit = new JRadioButtonMenuItem(unitItems[x]);
         item20Unit.addActionListener(this);
         start20Min.add(item20Unit);
         startMinTypes.add(item20Unit);
         item20Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeMinute = Integer.parseInt(event.getActionCommand()) + 20;
            updateDisplay();
            }
         });
      }
 
      JMenu start30Min = new JMenu("30");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item30Unit = new JRadioButtonMenuItem(unitItems[x]);
         item30Unit.addActionListener(this);
         start30Min.add(item30Unit);
         startMinTypes.add(item30Unit);
         item30Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeMinute = Integer.parseInt(event.getActionCommand()) + 30;
            updateDisplay();
            }
         });
      }
 
      JMenu start40Min = new JMenu("40");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item40Unit = new JRadioButtonMenuItem(unitItems[x]);
         item40Unit.addActionListener(this);
         start40Min.add(item40Unit);
         startMinTypes.add(item40Unit);
         item40Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeMinute = Integer.parseInt(event.getActionCommand()) + 40;
            updateDisplay();
            }
         });
      }
 
      JMenu start50Min = new JMenu("50");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item50Unit = new JRadioButtonMenuItem(unitItems[x]);
         item50Unit.addActionListener(this);
         start50Min.add(item50Unit);
         startMinTypes.add(item50Unit);
         item50Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeMinute = Integer.parseInt(event.getActionCommand()) + 50;
            updateDisplay();
            }
         });
      }
 
      startMinSubMenu.add(start00Min);
      startMinSubMenu.add(start10Min);
      startMinSubMenu.add(start20Min);
      startMinSubMenu.add(start30Min);
      startMinSubMenu.add(start40Min);
      startMinSubMenu.add(start50Min);
      startMenu.add(startMinSubMenu);
 
      /*
       * Assemble the submenus of the Start Time Menu for seconds.
       * Register a listener for the radio buttons.
       */
      ButtonGroup startSecTypes = new ButtonGroup();
      JMenu start00Sec = new JMenu("00");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item00Unit = new JRadioButtonMenuItem(unitItems[x]);
         item00Unit.addActionListener(this);
         start00Sec.add(item00Unit);
         startSecTypes.add(item00Unit);
         item00Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeSecond = Integer.parseInt(event.getActionCommand());
            updateDisplay();
            }
         });
      }
 
      JMenu start10Sec = new JMenu("10");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item10Unit = new JRadioButtonMenuItem(unitItems[x]);
         item10Unit.addActionListener(this);
         start10Sec.add(item10Unit);
         startSecTypes.add(item10Unit);
         item10Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeSecond = Integer.parseInt(event.getActionCommand()) + 10;
            updateDisplay();
            }
         });
      }
 
      JMenu start20Sec = new JMenu("20");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item20Unit = new JRadioButtonMenuItem(unitItems[x]);
         item20Unit.addActionListener(this);
         start20Sec.add(item20Unit);
         startSecTypes.add(item20Unit);
         item20Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeSecond = Integer.parseInt(event.getActionCommand()) + 20;
            updateDisplay();
            }
         });
      }
 
      JMenu start30Sec = new JMenu("30");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item30Unit = new JRadioButtonMenuItem(unitItems[x]);
         item30Unit.addActionListener(this);
         start30Sec.add(item30Unit);
         startSecTypes.add(item30Unit);
         item30Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeSecond = Integer.parseInt(event.getActionCommand()) + 30;
            updateDisplay();
            }
         });
      }
 
      JMenu start40Sec = new JMenu("40");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item40Unit = new JRadioButtonMenuItem(unitItems[x]);
         item40Unit.addActionListener(this);
         start40Sec.add(item40Unit);
         startSecTypes.add(item40Unit);
         item40Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeSecond = Integer.parseInt(event.getActionCommand()) + 40;
            updateDisplay();
            }
         });
      }
 
      JMenu start50Sec = new JMenu("50");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item50Unit = new JRadioButtonMenuItem(unitItems[x]);
         item50Unit.addActionListener(this);
         start50Sec.add(item50Unit);
         startSecTypes.add(item50Unit);
         item50Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            startTimeSecond = Integer.parseInt(event.getActionCommand()) + 50;
            updateDisplay();
            }
         });
      }
 
      startSecSubMenu.add(start00Sec);
      startSecSubMenu.add(start10Sec);
      startSecSubMenu.add(start20Sec);
      startSecSubMenu.add(start30Sec);
      startSecSubMenu.add(start40Sec);
      startSecSubMenu.add(start50Sec);
      startMenu.add(startSecSubMenu);
 
      /*
       * Assemble the submenus of the End Time Menu for minutes.
       * Register a listener for the radio buttons.
       */
      ButtonGroup endMinTypes = new ButtonGroup();
      JMenu end00Min = new JMenu("00");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item00Unit = new JRadioButtonMenuItem(unitItems[x]);
         item00Unit.addActionListener(this);
         end00Min.add(item00Unit);
         endMinTypes.add(item00Unit);
         item00Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeMinute = Integer.parseInt(event.getActionCommand());
            updateDisplay();
            }
         });
      }
 
      JMenu end10Min = new JMenu("10");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item10Unit = new JRadioButtonMenuItem(unitItems[x]);
         item10Unit.addActionListener(this);
         end10Min.add(item10Unit);
         endMinTypes.add(item10Unit);
         item10Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeMinute = Integer.parseInt(event.getActionCommand()) + 10;
            updateDisplay();
            }
         });
      }
 
      JMenu end20Min = new JMenu("20");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item20Unit = new JRadioButtonMenuItem(unitItems[x]);
         item20Unit.addActionListener(this);
         end20Min.add(item20Unit);
         endMinTypes.add(item20Unit);
         item20Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeMinute = Integer.parseInt(event.getActionCommand()) + 20;
            updateDisplay();
            }
         });
      }
 
      JMenu end30Min = new JMenu("30");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item30Unit = new JRadioButtonMenuItem(unitItems[x]);
         item30Unit.addActionListener(this);
         end30Min.add(item30Unit);
         endMinTypes.add(item30Unit);
         item30Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeMinute = Integer.parseInt(event.getActionCommand()) + 30;
            updateDisplay();
            }
         });
      }
 
      JMenu end40Min = new JMenu("40");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item40Unit = new JRadioButtonMenuItem(unitItems[x]);
         item40Unit.addActionListener(this);
         end40Min.add(item40Unit);
         endMinTypes.add(item40Unit);
         item40Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeMinute = Integer.parseInt(event.getActionCommand()) + 40;
            updateDisplay();
            }
         });
      }
 
      JMenu end50Min = new JMenu("50");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item50Unit = new JRadioButtonMenuItem(unitItems[x]);
         item50Unit.addActionListener(this);
         end50Min.add(item50Unit);
         endMinTypes.add(item50Unit);
         item50Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeMinute = Integer.parseInt(event.getActionCommand()) + 50;
            updateDisplay();
            }
         });
      }
 
      endMinSubMenu.add(end00Min);
      endMinSubMenu.add(end10Min);
      endMinSubMenu.add(end20Min);
      endMinSubMenu.add(end30Min);
      endMinSubMenu.add(end40Min);
      endMinSubMenu.add(end50Min);
      endMenu.add(endMinSubMenu);
 
      /*
       * Assemble the submenus of the End Time Menu for seconds.
       * Register a listener for the radio buttons.
       */
      ButtonGroup endSecTypes = new ButtonGroup();
      JMenu end00Sec = new JMenu("00");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item00Unit = new JRadioButtonMenuItem(unitItems[x]);
         item00Unit.addActionListener(this);
         end00Sec.add(item00Unit);
         endSecTypes.add(item00Unit);
         item00Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeSecond = Integer.parseInt(event.getActionCommand());
            System.out.println("endTimeSecond = " + endTimeSecond);
            updateDisplay();
            }
         });
      }
 
      JMenu end10Sec = new JMenu("10");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item10Unit = new JRadioButtonMenuItem(unitItems[x]);
         item10Unit.addActionListener(this);
         end10Sec.add(item10Unit);
         endSecTypes.add(item10Unit);
         item10Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeSecond = Integer.parseInt(event.getActionCommand()) + 10;
            updateDisplay();
            }
         });
      }
 
      JMenu end20Sec = new JMenu("20");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item20Unit = new JRadioButtonMenuItem(unitItems[x]);
         item20Unit.addActionListener(this);
         end20Sec.add(item20Unit);
         endSecTypes.add(item20Unit);
         item20Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeSecond = Integer.parseInt(event.getActionCommand()) + 20;
            updateDisplay();
            }
         });
      }
 
      JMenu end30Sec = new JMenu("30");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item30Unit = new JRadioButtonMenuItem(unitItems[x]);
         item30Unit.addActionListener(this);
         end30Sec.add(item30Unit);
         endSecTypes.add(item30Unit);
         item30Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeSecond = Integer.parseInt(event.getActionCommand()) + 30;
            updateDisplay();
            }
         });
      }
 
      JMenu end40Sec = new JMenu("40");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item40Unit = new JRadioButtonMenuItem(unitItems[x]);
         item40Unit.addActionListener(this);
         end40Sec.add(item40Unit);
         endSecTypes.add(item40Unit);
         item40Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeSecond = Integer.parseInt(event.getActionCommand()) + 40;
            updateDisplay();
            }
         });
      }
 
      JMenu end50Sec = new JMenu("50");
      for (int x=0; x < unitItems.length; x++) {
         JMenuItem item50Unit = new JRadioButtonMenuItem(unitItems[x]);
         item50Unit.addActionListener(this);
         end50Sec.add(item50Unit);
         endSecTypes.add(item50Unit);
         item50Unit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent event) {
            endTimeSecond = Integer.parseInt(event.getActionCommand()) + 50;
            updateDisplay();
            }
         });
      }
 
      endSecSubMenu.add(end00Sec);
      endSecSubMenu.add(end10Sec);
      endSecSubMenu.add(end20Sec);
      endSecSubMenu.add(end30Sec);
      endSecSubMenu.add(end40Sec);
      endSecSubMenu.add(end50Sec);
      endMenu.add(endSecSubMenu);
 
      /*
       * Assemble the submenus of the Help menu
       */
      JMenuItem subHelpItem = new JMenuItem("Instructions");
      subHelpItem.addActionListener(this);
      helpMenu.add(subHelpItem);
      helpMenu.addSeparator();
      subHelpItem = new JMenuItem("About");
      subHelpItem.addActionListener(this);
      helpMenu.add(subHelpItem);
 
      /*
       * Finally, add all the menus to the menubar
       */
      menuBar.add(fileMenu);
      menuBar.add(startMenu);
      menuBar.add(endMenu);
      menuBar.add(Box.createHorizontalGlue());
      menuBar.add(helpMenu);
   }
 
   public void actionPerformed(ActionEvent e) {
      JMenuItem source = (JMenuItem) (e.getSource());
 
      if(e.getActionCommand().equals("New")){
         System.out.println("Got New menu item");
      }
      else if(e.getActionCommand().equals("Save")){
         System.out.println("Got Save menu item");
      }
      else if(e.getActionCommand().equals("Print")){
         System.out.println("Got Print menu item");
      }
      else if(e.getActionCommand().equals("Exit")){
         System.out.println("Got EXIT menu item");
      }
      else if(e.getActionCommand().equals("c")){
         System.out.println("Got Start Time menu item");
      }
      else if(e.getActionCommand().equals("Instructions")){
         System.out.println("Got Instructions menu item");
         Instructions inst = new Instructions();
         inst.setVisible(true);
      }
      else if(e.getActionCommand().equals("About")){
         System.out.println("Got About menu item");
         MessageDialog md = new MessageDialog(this,
                            "PTC",
                            "Data Logger Dump Program",
                            "By",
                            "William G. Bogdanowich");
      }
   }
 
   /*
    * Add Components to Layout Manager
    */
   public static void addComponent (Container container, Component
                                    component, int gridx, int gridy,
                                    int gridwidth, int gridheight, int fill,
                                    int anchor, double weightx, double weighty)
                                    throws AWTException {
      LayoutManager lm = container.getLayout();
      if (!(lm instanceof GridBagLayout)) {
         throw new AWTException ("Invalid layout should be GridBagLayout not: "
                                  + lm);
      }
      else {
         GridBagConstraints gbc = new GridBagConstraints();
         gbc.gridx = gridx;           //column's upper left corner
         gbc.gridy = gridy;           //row's upper left corner
         gbc.gridwidth = gridwidth;   //Specify X columns in component
                                      //display area
         gbc.gridheight = gridheight; //Specify X rows in component display area
         gbc.fill = fill;             //components area will be positioned
         gbc.anchor = anchor;         //component will be positioned in area
         gbc.weightx = weightx;       //how to distribute extra space in width
         gbc.weighty = weighty;       //how to distribute extra space in hight
         ((GridBagLayout)lm).setConstraints(component,gbc);
         container.add(component, gbc);
      }
   }
 
 
   /*
    * Update Display Area for Selection of Time
    */
   public void updateDisplay() {
      startDisplay.removeAll();
      Label displayLabel = new Label("Start Time: " + startTimeMinute + ":" +
                                      startTimeSecond + "          " +
                                      "End Time: " + endTimeMinute + ":" +
                                      endTimeSecond);
      startDisplay.add(displayLabel, "Right");
      startDisplay.validate();
   }
 
   /*
    * Listener interface must implement, not used
    */
   public void windowClosed(WindowEvent e) {}
   public void windowIconified(WindowEvent e) {}
   public void windowOpened(WindowEvent e) {}
   public void windowClosing(WindowEvent e) {
      dispose();       // Release window resources
      System.exit(0);
   }
   public void windowDeiconified(WindowEvent e) {}
   public void windowActivated(WindowEvent e) {}
   public void windowDeactivated(WindowEvent e) {}
}
 
 


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: menus appear behind Container Posted: Mar 12, 2002 1:17 PM
Reply to this message Reply
I think using add(component) instead of addComponent(component) will solve that problem.

By the way, are you tring to break the record for the most number of lines of code in a single method?

William Bogdanowich

Posts: 5
Nickname: billbogs
Registered: Mar, 2002

Re: menus appear behind Container Posted: Mar 12, 2002 1:51 PM
Reply to this message Reply
Thank you
The problem was mixing awt and swing. I used Label not JLabel

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: menus appear behind Container Posted: Mar 12, 2002 6:53 PM
Reply to this message Reply
Yeah, this is the Z-order problem that bites just about everyone at some point, because it is easy to forget a leading J now and then. What happens is that the OS keeps track of the Z-order, a stacking order from back to front, of all the components to draw on the screen. The OS asks each component in back to front order to draw itself. Swing does the same thing when it draws all its own components.

When you mix AWT and Swing, what happens is Swing just asks for say a native Window on top of which it draws everything. But AWT asks for a native peer component for each AWT component.

So in your case the OS knew about the Window requested by Swing and the AWT Label. When it was time to draw, the OS first asked the Swing Window to draw itself, and it drew everything except the Label, including any dropped down menus. Then the OS asked the Label to draw itself, which overdraws anything behind it, including menus.

Flat View: This topic has 3 replies on 1 page
Topic: a site help you pass the certification exam Previous Topic   Next Topic Topic: problem while uploading files

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use