java - JFrame setComponentZOrder() changes size of the objects -


i'm trying write undecorated jframe. i'm trying put button on background label. setting button's z order causes button streches size of jframe , neither setbounds() nor setsize() changes situation. here code:

import javax.swing.*;  public class myapp {      public static void main(string[] args) {          jframe mainframe = new jframe();         mainframe.setbounds(0, 112, 100, 50);         mainframe.setlayout(null);         mainframe.setundecorated(true);          jlabel lblbackground = new jlabel(new imageicon(jframe.class.getresource("/res/green.png")));         lblbackground.setbounds(0, 0, 100, 50);          jbutton btnstart = new jbutton("");         btnstart.setbounds(5, 15, 10, 15);          mainframe.add(lblbackground);         mainframe.add(btnstart);         mainframe.setcomponentzorder(btnstart, 0);          mainframe.setcomponentzorder(btnstart, 1);            mainframe.setvisible(true);      }    }   

thanks replies.

use jlayeredpane this.

you need create new jlayeredpane: jlayeredpane layered = new jlayeredpane();

set jframe use content pane: mainframe.setcontentpane(layered);

and add components, in format: layered.add(component c, int layernumber);

hope works you!

more on jlayeredpanes


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -