java - Setting the JFrame background transparent making PopupMenu blank -


my question similar this, think has simpler example.

basically calling awtutilities.setwindowopaque(window, false) make background of jframe transparent, jpopupmenu show blank.

public class javaapplication8 {      jpopupmenu popup;     jmenuitem open;     jlabel bglabel = new jlabel("testing");      public static void main(string[] args) {         // todo code application logic here          jframe window = new jframe("test");          url bgurl = javaapplication8.class.getresource("images/bg.jpg");         imageicon bg = new imageicon(bgurl);          javaapplication8 test = new javaapplication8();         test.setpopupmenu();         test.bglabel.seticon(bg);          window.add(test.bglabel, borderlayout.center);          window.setundecorated(true);         awtutilities.setwindowopaque(window, false);                 //window.pack();         window.setsize(200, 200);         window.setdefaultcloseoperation(jframe.dispose_on_close);         window.setlocationrelativeto(null);         window.setvisible(true);      }      public void setpopupmenu(){         popup = new jpopupmenu();         open = new jmenuitem("test");          popup.add(open);         this.bglabel.setcomponentpopupmenu(popup);          }  } 

here's image of what's happening:

enter image description here enter image description here

what's interesting happens whenever click on right side of jframe. not sure why. keep in mind i'm not 100% sure awtutilities.setwindowopaque(window, false) indeed cause of problem, whenever delete line seems going fine.

edit: stated camickr, looks happens when popup menu not contained in bounds of parent window.

background: i'm not sure why using transparent / semi-transparent backgrounds causes problems heavyweight popups , how paint, -- regarless of whether or not use awtutilities.setwindowopaque(window, false) or frame.setbackground(new color(0, 0, 0, 0)).

the heavyweightpopups created when popup can't fit way inside target window. +user2280704 problem presents if click @ bottom of window. lightweightpopups not have problem -- hence, menus work in middle of window.

also, interesting note, typically menu render fine first time, not following times.

answer: i've come workaround invokes repaint after popups display. invoke following code when launch application.

popupfactory.setsharedinstance(new popupfactory()  {     @override     public popup getpopup(component owner, final component contents, int x, int y) throws illegalargumentexception     {         popup popup = super.getpopup(owner, contents, x, y);         swingutilities.invokelater(new runnable()         {             @override             public void run()             {                 contents.repaint();             }         });         return popup;     } }); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -