swing - java Gap between jframe and ImagePanel -


imgi have jlayeredpane adds 3 objects, problem backgroundimage when app runs there gap between jframe , background image top set (0,0) no matter change gap still there (i want rid of gap). if copy backgroundimage class , put in file/class gap not there. can help?

public class navigationmenu extends jpanel {  private arraylist<string> menu = new arraylist(); private int menusize; private int menuchannel = 0; private font realfont; private static dimension screensize = new dimension(new screendimensions().getscreenwidth(), new screendimensions().getscreenheight()); private static final int menu_height = (int)(new screendimensions().getscreenheight()*0.1); private static final int menu_width = new screendimensions().getscreenwidth(); private static final int menu_center = (new screendimensions().getscreenheight() / 2) - (menu_height / 2);  public navigationmenu() {      //add menu channels     setpreferredsize(screensize);     setbounds(0,0,menu_width,screensize.height);     this.menu.add("movies");     this.menu.add("music");     this.menu.add("pictures");     this.menu.add("videos");     this.menu.add("tv shows");     this.menu.add("weather");     this.menu.add("radio");     this.menu.add("settings");     this.menusize = menu.size() - 1;      jlayeredpane pfinal = new jlayeredpane();     jpanel _menutext = new menutext();     jpanel _backgroundimage = new backgroundimage("backgrounds/curtains.png");     jpanel _bar = new bar();      pfinal.setpreferredsize(screensize);     pfinal.setbounds(0,0,menu_width,screensize.height);      pfinal.add(_backgroundimage, new integer(1));     pfinal.add(_bar, new integer(2));     pfinal.add(_menutext, new integer(3));      add(pfinal); }  public class bar extends jpanel {     public bar() {         setbounds(0,menu_center,menu_width, menu_height);         setopaque(false);     }     @override     protected void paintcomponent(graphics g) {         graphics2d g2d = (graphics2d)g;         g2d.setrenderinghint(renderinghints.key_antialiasing, renderinghints.value_antialias_on);         g2d.setcomposite(alphacomposite.getinstance(alphacomposite.src_over, 0.8f));         g2d.setcolor(color.black);         g2d.fillrect(0,0,screensize.width,menu_height);     } }  public class menutext extends jpanel {      public menutext() {         setbounds(0,menu_center,menu_width,menu_height);         setopaque(false);         setfocusable(true);         requestfocusinwindow();          try {             realfont = new realfont(((int)(menu_height * 0.80))).getrealfont();         } catch (exception e) {             system.out.println(e.tostring());         }         addkeylistener(new keyadapter() {             @override             public void keypressed(keyevent e) {                 //joptionpane.showmessagedialog(null, "ok");                 int keycode = e.getkeycode();                     switch (keyevent.getkeytext(keycode)) {                         case "up":                             //joptionpane.showmessagedialog(null, "up");                             if(menuchannel < menusize) {                                 menuchannel++;                                  repaint();                             } else {                                 menuchannel = 0; //reset                                 repaint();                             }                         break;                         case "down":                             if(menuchannel == 0) {                                 menuchannel = menusize + 1;                                 menuchannel--;                                 repaint();                             } else {                                 menuchannel--;                                 repaint();                             }                            break;                     }             }         });     }      @override     protected void paintcomponent(graphics g) {         graphics2d g2d = (graphics2d)g;         string menustring = menu.get(menuchannel);         g2d.setrenderinghint(renderinghints.key_antialiasing, renderinghints.value_antialias_on);         //g2d.setbackground(color.pink);         //g2d.fillrect(0,0,getwidth(),getheight());         g2d.setcolor(color.white);         g2d.setfont(realfont);         fontrendercontext context = g2d.getfontrendercontext();         java.awt.geom.rectangle2d rect = realfont.getstringbounds(menustring, context);         int textheight = (int)rect.getheight();         int textwidth = (int)rect.getwidth();         int panelheight = getheight();         int panelwidth = getwidth();         int x = (panelwidth - textwidth) / 2;         int y = (panelheight - textheight) / 2;         //system.out.println("f:"+ fontmetrics.getth:" + textheight + "\ntw:" + textwidth + "\nph:" + panelheight + "\npw:" + panelwidth);         g2d.drawstring(menustring,x,(float)-rect.gety()+2);     } }  public class backgroundimage extends jpanel {      private image icon;     private int screenwidth = new screendimensions().getscreenwidth();     private int screenheight = new screendimensions().getscreenheight();      public backgroundimage(string background) {         icon = new imageicon(background).getimage();         dimension size = new dimension(screenwidth,screenheight);         setpreferredsize(size);         setminimumsize(size);         setmaximumsize(size);         setsize(size);         setlayout(null);      }      @override     protected void paintcomponent(graphics g) {         g.drawimage(icon,0,0,screensize.width,screensize.height,null);     } } } 

change navigationmenu's layout borderlayout


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -