Sub-Menus are displaying away from their parent Menu for first time.

Hi All,
I have a problem with sub-menus display location. In my application, I have a JPopupMenu to which several sub-menus (*JMenu*) are added. All the JMenuItems inside JMenu are having an Icon (Image) along with menu item title. I am providing a facility to change the font size of Menu Item names as well as the ImageIcon size dynamically through a dialog box. When the size is changed to larger value than the existing, the menus as well as submenus are getting displayed correctly. But when I change the size of ImageIcon and the font to smaller value than the existing one, then the submenus are getting displayed away from their parent menu for the first time. The location of sub menu display is matching with the location when their size was larger. This problem appears only for the first display of sub menus after their sizes are changed. For the successive display, the locating is resetting automatically to correct location.
So can anybody help me out about how to display submenus at correct location irrespective of font and image size changes for the first time also? Is there any event which gets fired when we change the font size or ImageIcon sizes? Is there any specific method to refresh the menu sizes if any of such properties (such as font size, ImageIcon size) are changed?
If you need any additional information, feel free to ask.

Below is the sample code for the query I placed. Steps to reproduce the problem are:
1. Click on "Increase Font" button.
2. Generate the popup at the right side corner of the screen (using right mouse click) such that the sub menu of edit should appear at left side of "Edit" option.
3. Click on "Decrease Font" button.
4. Generate the popup at the right side corner of the screen (using right mouse click) such that the sub menu of edit should appear at left side of "Edit" option.
You will see that sub menu of edit menu is displayed away from the popup for the first time. The sub menu location matches with previous location when its font size was larger. Location resets automatically for the next successive displays.
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
public class JPopupDemo implements ActionListener {
  public static Font newFont=new Font("Times New Roman", Font.BOLD,24);
  JFrame frame = null;
  JPopupMenu popupMenu = null;
  JMenuItem fileMenu = null;
  JMenu editMenu = null;
  JMenuItem cutMenuItem = null;
  JMenuItem copyMenuItem = null;
  JMenuItem pasteMenuItem = null;
  JMenuItem findMenuItem = null;
    JPopupDemo(){
    frame = new JFrame("Popup Example");     
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    popupMenu = new JPopupMenu();
    fileMenu = new JMenuItem("File");
    editMenu = new JMenu("Edit");
    cutMenuItem = new JMenuItem("Cut");
    editMenu.add(cutMenuItem);
    copyMenuItem = new JMenuItem("Copy");
    editMenu.add(copyMenuItem);
    pasteMenuItem = new JMenuItem("Paste");
    pasteMenuItem.setEnabled(false);
    editMenu.add(pasteMenuItem);
    editMenu.addSeparator();
    findMenuItem = new JMenuItem("Find");
    editMenu.add(findMenuItem);
    popupMenu.add(fileMenu);
    popupMenu.add(editMenu);
    MouseListener mouseListener = new JPopupMenuShower(popupMenu);
    frame.addMouseListener(mouseListener);
    //frame.setSize(350, 250);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension dim = toolkit.getScreenSize();
    frame.setSize(dim.width,dim.height-100);
    JButton incrButton = new JButton("Increase Size");
    incrButton.setActionCommand("IncreaseSize");
    incrButton.addActionListener(this);
    JButton decrButton = new JButton("Decrease Size");
    decrButton.setActionCommand("DecreaseSize");
    decrButton.addActionListener(this);
    Container cp = frame.getContentPane();
    cp.setLayout(new BorderLayout());
    JPanel jp = new JPanel();
    jp.add(incrButton);
    jp.add(decrButton);
    cp.add(jp,BorderLayout.SOUTH);
    frame.setVisible(true);
public static void main(String args[]) {
     JPopupDemo demo = new JPopupDemo();
  public void actionPerformed(ActionEvent ae)
        if (ae.getActionCommand().equals("IncreaseSize"))
               newFont = new Font("Times New Roman", Font.BOLD,48);
               setNewFont();
          else if (ae.getActionCommand().equals("DecreaseSize"))
               newFont = new Font("Times New Roman", Font.BOLD,12);
               setNewFont();
   public void setNewFont()
        popupMenu.setFont(newFont);
        fileMenu.setFont(newFont);
        editMenu.setFont(newFont);
        cutMenuItem.setFont(newFont);
        copyMenuItem.setFont(newFont);
        pasteMenuItem.setFont(newFont);
        findMenuItem.setFont(newFont);
class JPopupMenuShower extends MouseAdapter {
  private JPopupMenu popup;
  public JPopupMenuShower(JPopupMenu popup) {
    this.popup = popup;
  private void showIfPopupTrigger(MouseEvent mouseEvent) {
    if (popup.isPopupTrigger(mouseEvent)) {
      popup.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent
          .getY());
  public void mousePressed(MouseEvent mouseEvent) {
    showIfPopupTrigger(mouseEvent);
  public void mouseReleased(MouseEvent mouseEvent) {
    showIfPopupTrigger(mouseEvent);
}Edited by: VPKVL on Aug 4, 2008 1:18 AM

Similar Messages

  • Tell if you are far away from GPS-coordinates

    I am thinking of building an iPhone app. Today I saw a man sitting on the bus, and he fell asleep. After plenty of bus stops he woke up.
    I want to make an app that gives you an alert before you reach the place you are reaching (by map) and that will be GPS-coordinates I guess. Lets say 500m before.
    Is it possible?
    Message was edited by: cordoprod

    MapKit provides the basics for determining location.
    The app would need to know the latitude & longitude of the destination, then it would simply compare the current location...just like any GPS app.
    When the offset equals a certain distance, an alarm is triggered such as"You are approaching your destination"...just like any GPS app/device that has a clear view of the sky.
    As long as no one calls the phone to say "You are approaching your destination" when the user is 1,501 yards away from their stop, the app could tell the user "You are approaching your destination"...just like any good GPS app.

  • After the last update of Firefox, my toolbar menu became blank but the bookmarks are still available from a pulldown menu. I want the on the toolbar like they used to be. How do I recover this?

    After the last update of Firefox, my toolbar menu became blank but the bookmarks are still available from a pulldown menu. I want the on the toolbar like they used to be. How do I recover this?

    ''Attaboyslim wrote:''
    I am locked into firefox.
    If nothing happens when you press the F11 key, check if you have the same problem in Safe Mode.
    * [[Troubleshoot Firefox issues using Safe Mode]]
    ''Attaboyslim wrote:''
    I'd like the old browser please.
    * [[How to make the new Firefox look like the old Firefox]]

  • ADF application taking more time for first time and less from second time

    Hi Experts,
    We are using ADF 11.1.1.2.
    Our application contains 5 jsp pages, 10 - 12 taskflows, and 50 jsff pages.
    For the first time in the day if we use the application it is taking more than 60 sec on some actions.
    And from the next time onwords it is taking 5 to 6 sec.
    Same thing is happening daily.
    Can any one tell me why this application is taking more time for first time and less time from second time.
    Regards
    Gayaz

    Hi,
    If you don't restart you WLS every day, then you should read about Tuning Application Module Pools and Connection Pools
    http://docs.oracle.com/cd/E15523_01/web.1111/b31974/bcampool.htm#sm0301
    And pay attention to the parameter: Maximum Available Size, Minimum Available Size
    http://docs.oracle.com/cd/E15523_01/web.1111/b31974/bcampool.htm#sm0314
    And adjust them to suit your needs.

  • HT201250 i am using for first time the time machine and an external hard drive because I want to erase my macbook and start from zero files. do i keep my files in the portable hard disk when I connect it again with the macbook or the time machine will era

    i am using for first time the time machine and an external hard drive because I want to erase my macbook and start from zero files. Am i keeping my files in the portable hard disk when I will connect it again with the macbook or the time machine will erase all?
    I would like to know if after I erase all my data, empy hard drive inside the macbook, the time machine will erase all my files that I have saved in my "WD "My passport" external hard drive

    Welcome to Apple Support Communities
    Time Machine has to erase the external disk in order to make backups. Before setting Time Machine up, copy the files of your external disk to the hard disk of the Mac in order not to lose them, and then, set up Time Machine. The first backup will start automatically.
    If you want more information about Time Machine, read the Pondini's site > http://pondini.org

  • What should I do to setup a new MacBook pro for first time when moving from a PC?

    What should I do to setup a new MacBook pro for first time when moving from a PC?

    you have to use the migration assistant if you want your files transfered from your pc to mac this link will be helpful
    http://support.apple.com/kb/HT4796

  • I just purchased Lightroom 5 back on 15th of February, and v6 is now available. Do I understand correctly that I have to buy the new version for $149.00? Free updates are not available/included with the purchase for some time after the purchase?

    I just purchased Lightroom 5 back on 15th of February, and v6 is now available. Do I understand correctly that I have to buy the new version for $149.00? Free updates are not available/included with the purchase for some time after the purchase?

    Do I understand correctly that I have to buy the new version for $149.00?
    You can upgrade for $79.
    Products

  • HT204380 help. tried for first time to use FaceTime with another iPhone user & it would not work. "FaceTime failed". we are both on wi-fi networks & iTunes accounts are set up correctly.

    help. tried for first time to use FaceTime with another iPhone user & call refused to connect. Call would dial, allow us to accept call, then error message "FaceTime failed" would appear & call disconnect. we are both on wi-fi networks, both phones have updated software & both enabled FaceTime with iTunes logged in. don't know what else to do to get FaceTime to connect. Someone please help.

    Thanks Helen for the response. At least you can get some of the contacts to work. Absolutely none of mine will. Feel like my phone is cheating me out something it should do. Think I'm going to just have to dump all the Apple products in general because this phone hasn't worked right since I got it.

  • HT4859 i have setup an ipad without connecting to computer, i am now connecting for first time to itunes it asks if i want to set up as new ipad or restore from previous backup (my iphone not ipad), i have backed ipad up to icloud when i connect back to i

    i have set up my wifes ipad mini wirelesly, i am now connecting for first time to itunes it asks if i want to set up as new ipad or restore from previous backup (my iphone not ipad), i have backed ipad up to icloud when i connect back to itunes will it give me an option to restore from icloud, i dont want to lose the apps and data my wife has already installed through her account... any thoughts

    1. set up as new
    2. transfer you wife's purchases.
    3. Just in case create one computer back up manually.
    Enjoy.

  • HT5312 Hi I forgot my security question how I can rest becouse I was going APP this massage pop of in the app page I benn buying app in this iPod may time they are say for first time you are buying apps in iPod pls I need your help to resist my security q

    Hi I forgot my security question how I can rest becouse I was going APP this massage pop of in the app page I benn buying app in this iPod may time they are say for first time you are buying apps in iPod pls I need your help to resist my security question

    The Three Best Alternatives for Security Questions and Rescue Mail
         1.  Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
         2.  Call Apple Support in your country: Customer Service: Contact Apple support.
         3.  Rescue email address and how to reset Apple ID security questions.
    A substitute for using the security questions is to use 2-step verification:
    Two-step verification FAQ Get answers to frequently asked questions about two-step verification for Apple ID.

  • Menu and sub menus are showing in the popup window

    Hi,
    We have seach PG, summary and Detail PG.
    When we clicked on summary page link, detail page is opening in popup window.
    JavaScript is used for this and toolbar=no,menubar=no used .
    Still menus are showing below Oracle Branding image.
    How to hide these?
    Thanks
    JP

    hello, what do you see instead? please note that at the moment firefox hello also won't work when you've set up the browser to run in permanent private browsing mode ("never remember history" in the options > privacy panel).
    [[Settings for privacy, browsing history and do-not-track]]

  • Cannot get sub menus to cascade correctly from horizontal menu.

    Horizontal menu looks beautiful but the sub menus no longer go straight down, instead they go down and to the left and pile up on each other no mater what I do. How do I fix this? @

    Horizontal menu looks beautiful but the sub menus no longer go straight down, instead they go down and to the left and pile up on each other no mater what I do. How do I fix this? @

  • How to display a seperate right click menu for each item of a tree control?

    Hi I want to display a specific right click menu when a particular tree item is selected. I know how to create a menu and how to display it. I am using the function GetLabelFromIndex() to get the active tree item and then compare the label and based on the result display a manu for that item. Now my problem is that when I use the above function in the EVENT_RIGHT_CLICK it gives me the error "the Index passed is out of range" while using the same function with the same arguments in EVENT_SELECTION_CHANGE it gives no error...below is the part of my code
    case EVENT_RIGHT_CLICK:
    GetLabelFromIndex(panelHandle, PANEL_TREE, eventData2, label1);
    //The function gives the stated error here
    if(eventData1)//after it I compare the result and display the menu
    case EVENT_SELECTION_CHANGE:
    GetLabelFromIndex (panelHandle, PANEL_TREE, eventData2, label1);
    //The function works fine here
    if (eventData1)
     If any one have any idea whats going on or alternate way of doing this Please share knowledge...Thanks
    If you are young work to Learn, not to earn.

    Hi,
    one possible approach of solving this problem is looking closer at the error message: The error "the Index passed is out of range" tells you that something is wrong with the index, either it is too small or too large So why don't you set a breakpoint and check the index value, it might be useful information...
    The other hint is to check the meaning of eventdata2 (using the help): It is different for different events! For the event_right_click it gives the horizontal mouse position, not the index as event_selection_change does...

  • Urgent: Getting FRM-41211 when calling reports from forms for first time.

    Hi,
    We are running into the FRM-41211 error, when the users try to call a report from a form. The report is called from a form in SYNCHRONOUS mode. This is the only report that is being called. No other report is
    running at that time when the users get this error. This is happening only the first time when they try to call the report from the form. After getting this error, when they click on OK, and when they try to call this
    report again, the report works fine.
    Any ideas?? It's urgent...
    Thanks
    Vamshi.
    null

    Maybe try to use "run_report_product"?

  • Using Bulk Scenario to Capture Data from Source for First time

    Hi,
    I need to setup ODI for a table between two Database. Genereally, I follow practice of importing oracle  dump of table into target database for the first time before delta capture preocess starts. However, this time there is space constraint at source system & we can not create the oracle dump as it will result into 120-130 GB.
    Is it possible to import these one time data into target Database via ODI Bulk Schenario. Does ODI have any timeouts set at the database connetion as this will take long running session to copy across such a huge data. Will it cause any time outs at Database.
    Please suggest.
    Thanks.

    Hi All,
    Thanks a lot for your responses. Moving ahead and trying out different things, i figured out that the EPMA/Planning had to be on the same machine as the ERPI. After installing EPMA/Planning on the same machine, the ERPI target application registration page started displaying all the applications created using the EPMA and i also successfully registered my target planning application with ERPI. But you know life is not that fair, right after the resolution of this problem, another problem appeared :(. While registering the target planning application, EPMA was by default selected as the Metadata Load method and i selected FDM as the data load method.
    After registering the application, i happily started adding the metadata rule as instructed in the knowledge document 951369.1 (Thanks user735469 for the reference), but when i clicked on the Add Dimension button, the next page gave an error stating There are no more dimensions remaining to be mapped under this application. and the dimensions drop down under the target application area was empty.
    According to this link http://download.oracle.com/docs/cd/E12825_01/epm.111/readme/fdm_11113_readme.html , this error can be fixed by clicking on the refresh button but i couldnt find a refresh button on the entire page. I tried refreshing the browser but to vain. I also downloaded and applied latest ERPI patch but still no positive results.
    Any idea why is this happening ?
    Desperately waiting for your help. :(
    Thanks & Regards,
    Muhammad Jamshaid Nawaz

Maybe you are looking for