java - How to overlay a Jbutton over a JprogressBar -
i'm working on swing gui, , i'd overlay button on progressbar. have wrote code update progress bar , button event, don't know how manage layout!
currently panel code following:
public static void main(string[] args) throws ioexception { jframe myframe = new jframe("myjftitle"); myframe.setlayout(new borderlayout()); jpanel mypanel = new jpanel(); jbutton mybutton = new jbutton("click me"); jprogressbar mybar = new jprogressbar(); mybar.setvalue(50); mypanel.add(mybutton); mypanel.add(mybar); myframe.add(mypanel,borderlayout.center); myframe.setvisible(true); }
which gives following result:
i'm trying unsuccesfully obtain this:
can explain me kind of layout (or whatever) should use, or link me same reference can read how it??
update:
by adding following code, managed overly 2 components, m still not able enlarge progress bar fit panel size:
layoutmanager overlay = new overlaylayout(mypanel); mypanel.setlayout(overlay);
try this:
public class test { public static void main(string[] args) throws ioexception { jframe myframe = new jframe("myjftitle"); myframe.setlayout(new borderlayout()); jbutton mybutton = new jbutton("click me"); mybutton.setalignmentx(component.center_alignment); jprogressbar mybar = new jprogressbar(); layoutmanager overlay = new overlaylayout(mybar); mybar.setlayout(overlay); mybar.setvalue(50); mybar.add(mybutton); myframe.add(mybar, borderlayout.center); myframe.pack(); myframe.setsize(new dimension(300,100)); myframe.setvisible(true); } }
Comments
Post a Comment