java - Background image on JFrame -


this question has answer here:

i begin in java programming language. make jframe , put background image on , above jframe, insert widgets : jtextarea , jbutton ... can not overlap. here code :

public void go() {     cadre = new jframe("premiere feneêtre");     cadre.setdefaultcloseoperation(windowconstants.exit_on_close);     cadre.setsize(600, 600);     cadre.setvisible(true);`      borderlayout agencement = new borderlayout();     jpanel arriereplan = new jpanel(agencement);     arriereplan.setborder(borderfactory.createemptyborder(10, 10, 10, 10));      box boiteaboutons = new box(boxlayout.page_axis);     boiteaboutons.setsize(150,150);     boiteaboutons.setopaque(false);     //boiteaboutons.setbackground(color.yellow);     b1 = new jbutton("bouton 1");     b1.addactionlistener(this);     b2 = new jbutton("bouton 2");     b2.addactionlistener(this);     b3 = new jbutton("bouton 3");     boiteaboutons.add(b1);     boiteaboutons.add(b2);     boiteaboutons.add(b3);     zonetexte = new jtextarea();      panneau p1 = new panneau();     arriereplan.add(borderlayout.south, boiteaboutons);     arriereplan.add(borderlayout.north,zonetexte);      cadre.getcontentpane().add(p1);     cadre.getcontentpane().add(arriereplan);  }  public class panneau extends jpanel {     public void paintcomponent(graphics g){         try {             image img = imageio.read(new file("c:/users/........png"));             //g.drawimage(img, 10, 10, this);             g.drawimage(img, 10, 10, this.getwidth(), this.getheight(), this);         } catch (ioexception e) {             e.printstacktrace();         }     } } 

i've read several things here regarding problem encounter, nothing helped me .

thank sorry bad english

cadre.getcontentpane().add(p1); cadre.getcontentpane().add(arriereplan); 

you can't add multiple component center of borderlayout.

instead want add component image panel:

panneau p1 = new panneau(); p1.setlayout( new borderlayout() ); p1.add(boiteaboutons, borderlayout.south); p1.add(zonetexte, borderlayout.north); cadre.add(p1); 

in future search forum before asking question (the topic title contains keywords start with). can see posting found under related heading on right side of page, question asked frequently.


Comments

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -