swing - How to alignment right to left in JFrame/java? -


i wrote code, i'm having problem making align right left. tried several things, none of them works. know can done playing coordinates, want way wouldn't need every word. how supposed right way?

code:

import java.util.*; import javax.swing.*; import java.awt.*;    public class gui { //messages  public static final string connectc_msg    = "התחבר"    ; public static final string disconnectc_msg = "התנתק"    ; public static final string serverlbl_msg   = "שרת יעד:"  ; public static final string usernamelbl_msg = ":שם משתמש"; public static final string passwordlbl_msg = ":סיסמא"   ; public static final string portlbl_msg     = ":פתחה"    ; //sizes public static final int srevertxtfield_width   = 10; public static final int usernametxtfield_width = 10; public static final int passwordtxtfield_width = 10; public static final int porttxtfield_width     = 5 ; public static final int window_width  = 800; public static final int window_height = 200;   static jframe frame1; static container pane;  static jbutton btnconnect = new jbutton(connectc_msg),                btidiscinnect = new jbutton(disconnectc_msg); static jlabel lblserver   = new jlabel(serverlbl_msg),               lblusername = new jlabel(usernamelbl_msg),               lblpassword = new jlabel(passwordlbl_msg),               lblport     = new jlabel(portlbl_msg);  static jtextfield txtserver   = new jtextfield(srevertxtfield_width),                   txtusername = new jtextfield(usernametxtfield_width),                   txtport     = new jtextfield(porttxtfield_width);  static jpasswordfield txtpassword = new jpasswordfield(passwordtxtfield_width);  static insets insets;   public static void main(string[] args) {     frame1 = new jframe ("הדגמה");     frame1.setsize(window_width,window_height);     frame1.setcomponentorientation(componentorientation.right_to_left);     pane = frame1.getcontentpane();     pane.setcomponentorientation(componentorientation.right_to_left);      insets = pane.getinsets();     pane.setlayout(null);        pane.add(lblserver);     pane.add(lblusername);     pane.add(lblpassword);     pane.add(lblport);     pane.add(txtserver);     pane.add(txtusername);     pane.add(txtpassword);     pane.add(txtport);     lblserver.setbounds((int)(insets.right),insets.top,             lblserver.getpreferredsize().width, lblserver.getpreferredsize().height);     txtserver.setbounds(lblserver.getx()+lblserver.getwidth(), lblserver.gety()+lblserver.getheight(),             txtserver.getpreferredsize().width, txtserver.getpreferredsize().height);      frame1.setvisible(true);  } 

}

try like:

jpanel panel = new jpanel( new flowlayout(flowlayout.right) ); panel.add(...); panel.add(...); ... frame.add(panel, borderlayout.north); 

and components align ride side of frame.

also, rid of static variables. not way write class.

read section swing tutorial on how use flow layout more information , examples. if show better way structure class without static stuff.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -