java - JPanel - positioning element -


i have problem setting position 1 of elements (the image). cannot align right-bottom of screen. tried use different layouts can't make work want it.

below url view how looks now. image in right-bottom it's new borderlayout , creates space on bottom prefer fit rest. red square shows image should placed.

image alignment

below code of program:

import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.util.*;  public class server extends jframe implements actionlistener{ public static final int port = 8060; private jbutton reset, exit; private jeditorpane messages; private imageicon logo = new imageicon("c:src\\images\\logo.png"); private jlabel logospot; container box = getcontentpane(); public static void main(string args[]){     new server().networking(); }  public void makemenu(){     jpanel menu = new jpanel();     reset = new jbutton("reset messages");     exit = new jbutton("exit");     menu.add(reset);     menu.add(exit);     reset.addactionlistener(this);     exit.addactionlistener(this);     box.add(menu, borderlayout.east); } public void setlogo(){     jpanel logospace = new jpanel(new borderlayout());     logospot= new jlabel();     logospot.seticon(logo);     logospace.add(logospot, borderlayout.east);     box.add(logospace, borderlayout.south); } public void makescreen(){     jpanel screen = new jpanel();     messages = new jeditorpane();     messages.setpreferredsize(new dimension(800,590));     screen.add(messages);     box.add(screen, borderlayout.west);     } public server(){     makemenu();     makescreen();     setlogo();     setdefaultcloseoperation(jframe.exit_on_close);     setvisible(true);     setsize(1024, 680);     settitle("emergency system"); } @override public void actionperformed(actionevent e){     if(e.getsource() == exit){         super.dispose();     }     if(e.getsource() == reset){         messages.settext(" ");     } } public void networking(){     string received=" ";     try{         serversocket ss = new serversocket(port);         while(true){             socket sock = ss.accept();             bufferedreader in =                      new bufferedreader(new inputstreamreader(                             sock.getinputstream()));             received = in.readline();             messages.settext(messages.gettext() + received +                      " \n\n");             outputstreamwriter out =                      new outputstreamwriter(sock.getoutputstream());             bufferedwriter bw = new bufferedwriter(out);             bw.write(received);             bw.flush();         }     }catch(exception e){         e.printstacktrace();     } }     } 

this should trick. needed more panels constrain 2nd image (160x160px) page_end , line_end of borderlayout instances.

send_messages

import java.awt.*; import java.awt.image.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.util.*;  public class server extends jframe implements actionlistener{      public static final int port = 8060;     private jbutton reset, exit;     private jeditorpane messages;     private imageicon logo = new imageicon(         new bufferedimage(140,140,bufferedimage.type_int_rgb));     private jlabel logospot;     container box = getcontentpane();      public static void main(string args[]){         new server();     }      public void makemenu(){         jpanel menu = new jpanel(new borderlayout(5,5));          menu.setbackground(color.red);         reset = new jbutton("reset messages");         exit = new jbutton("exit");          jpanel buttons = new jpanel();         buttons.setbackground(color.green);         menu.add(buttons, borderlayout.page_start);         buttons.add(reset);         buttons.add(exit);         reset.addactionlistener(this);         exit.addactionlistener(this);          jlabel l = new jlabel(new imageicon(new bufferedimage(             160,160,bufferedimage.type_int_rgb)));         jpanel forceright = new jpanel(new borderlayout());         forceright.add(l, borderlayout.line_end);         forceright.setbackground(color.blue);          menu.add(forceright, borderlayout.page_end);          box.add(menu, borderlayout.east);     }      public void setlogo(){         jpanel logospace = new jpanel(new borderlayout());         logospot= new jlabel();         logospot.seticon(logo);         logospace.add(logospot, borderlayout.east);         box.add(logospace, borderlayout.south);     }      public void makescreen(){         jpanel screen = new jpanel();         screen.setbackground(color.yellow);         messages = new jeditorpane();         messages.setpreferredsize(new dimension(800,590));         screen.add(messages);         box.add(screen, borderlayout.west);     }      public server(){         makemenu();         makescreen();         setlogo();         setdefaultcloseoperation(jframe.exit_on_close);         setvisible(true);         setsize(1024, 680);         settitle("emergency system");     }      @override     public void actionperformed(actionevent e){         if(e.getsource() == exit){             super.dispose();         }         if(e.getsource() == reset){             messages.settext(" ");         }     } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -