java - Creating GUI with using border layout Swing -


i'm trying create gui java. gui simple. can see want here : http://sketchtoy.com/64839370

in order that, have decided use borderlayout suggested on web. have 2 jpanel object , have put them jframe layout borderlayout. can see simplified code below :

private display display= new display(); // display extends jpanel  public simulation()     {         super();         // frame settings          settitle("label of jframe ");         setdefaultcloseoperation(exit_on_close);         setbounds(100,100,1094,560);             contentpane=this.getcontentpane();         setresizable(false);          contentpane.setlayout(new borderlayout());          try {             leftpanellogo=imageio.read(new file("logo.png"));         } catch (ioexception e) {             // todo auto-generated catch block             e.printstacktrace();         }          // generate left panel (information panel)         leftpanel=new jpanel(){             @override             public void paintcomponent(graphics g)             {                 super.paintcomponent(g);                 graphics2d g2d=(graphics2d)g;                 g2d.drawimage(leftpanellogo, 10, 250, null);             }         };         //leftpanel.setlayout(null);          // add panels contentpane            leftpanel.setbackground(color.white);         display.setbackground(color.black);          contentpane.add(leftpanel,borderlayout.west);         contentpane.add(display,borderlayout.center); } 

in display class constructor have following code:

try          {             bgpicture = imageio.read(new file("bg.jpg"));         }          catch (ioexception e)          {             e.printstacktrace();         } 

when run code, saw screen fulfilled panel on center, , not see leftpanel, (in other words, screen black since set background of display panel black)

so, how fix ?

enter image description here

import java.awt.*; import java.awt.image.bufferedimage; import javax.swing.*; import javax.swing.border.emptyborder;  public class logolayout {      private jcomponent ui = null;      logolayout() {         initui();     }      public void initui() {         if (ui!=null) return;          ui = new jpanel(new borderlayout(4,4));         ui.setborder(new emptyborder(4,4,4,4));          bufferedimage logo = new bufferedimage(                 276,560,bufferedimage.type_int_rgb);          /* that's needed */         ui.add(new jlabel(new imageicon(logo)), borderlayout.line_start);         ui.add(new jtextarea("display", 3, 44));         /* that's needed */     }      public jcomponent getui() {         return ui;     }      public static void main(string[] args) {         runnable r = new runnable() {             @override             public void run() {                 try {                     uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname());                 } catch (exception usedefault) {                 }                 logolayout o = new logolayout();                  jframe f = new jframe("logo layout");                 f.setdefaultcloseoperation(jframe.dispose_on_close);                 f.setlocationbyplatform(true);                  f.setcontentpane(o.getui());                 f.pack();                 f.setminimumsize(f.getsize());                  f.setvisible(true);             }         };         swingutilities.invokelater(r);     } } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -