Java - JLabel lose image and a new appear on front -
i have big jlabel picture, i'd user enters mouse on it, lose image , others small pictures appear in it, close each other. family tree, main image tree, , when mouse entered, small pics of plebs appear next each other, pic below. use:
jlabel c = new jlabel(); c.setborder(new etchedborder(etchedborder.raised)); c.seticon(new imageicon("c:\\users\\lud\\desktop\\family\\tree.png")); c.setbackground(new color(192, 192, 192)); c.setopaque(true); c.setbounds(5, 5, 256, 256); c.addmouselistener(new mouseadapter() { public void mouseentered(mouseevent me) { c.seticon(null); jlabel c1 = new jlabel(); c1.seticon(new imageicon("c:\\users\\lud\\desktop\\family\\george.png")); c1.setbounds(10, 10, 32, 32); add(c1); } public void mouseexited(mouseevent me) { } }); add(c);
the main jlabel/tree image appears fine when enter mouse on it, loses picutes without displaying new 1 above it. do wrong? thanks
don't create new jlabel, rather set icon on existing jlabel.
as side recommendation, please understand while null layouts , setbounds() might seem swing newbies easiest , best way create complex gui's, more swing gui's create more serious difficulties run when using them. won't resize components when gui resizes, royal witch enhance or maintain, fail when placed in scrollpanes, gawd-awful when viewed on platforms or screen resolutions different original one.
Comments
Post a Comment