java - Set position of buttons -


i having issues alignment. below have posted code , picture of current jframe.

code:

public void initui() {     try {         uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname());         jframe.setdefaultlookandfeeldecorated(true);         jpopupmenu.setdefaultlightweightpopupenabled(false);         simpledateformat sdf = new simpledateformat("h:mm:ss a");         string date = sdf.format(new date());         frame = new jframe("" + clientsettings.server_name +  " | " +checkday() + " - " + date);         frame.setlayout(new borderlayout());         frame.setresizable(false);         frame.setdefaultcloseoperation(jframe.exit_on_close);         jpanel gamepanel = new jpanel();          gamepanel.setlayout(new borderlayout());         gamepanel.add(this);         gamepanel.setpreferredsize(new dimension(765, 503));           initmenubar();         frame.getcontentpane().add(gamepanel, borderlayout.center);         frame.pack();           frame.setvisible(true); // can see client         frame.setresizable(false); // resizeable frame          init();     } catch (exception e) {             e.printstacktrace();     } }  public void initmenubar() {         jmenu filemenu = new jmenu("links");         string[] mainbuttons = new string[] { "forums", "-", "exit" };         (string name : mainbuttons) {             jmenuitem menuitem = new jmenuitem(name);             if (name.equalsignorecase("-")) {                 filemenu.addseparator();             } else if(name.equalsignorecase("forums")) {                 jmenu forumsmenu = new jmenu("forums");                 filemenu.add(forumsmenu);                 jmenuitem runeserver = new jmenuitem("rune-server");                 runeserver.addactionlistener(this);                 forumsmenu.add(runeserver);             } else {                 menuitem.addactionlistener(this);                 filemenu.add(menuitem);             }         }          jmenubar menubar = new jmenubar();         jmenubar jmenubar = new jmenubar();         jmenu settings = new jmenu("settings");         settings.setactioncommand("settings");         settings.addactionlistener(this);         jbutton screenshot = new jbutton("screenshot");         screenshot.setactioncommand("screenshot");         screenshot.addactionlistener(this);         frame.add(jmenubar);         menubar.add(filemenu);         menubar.add(screenshot);         menubar.add(settings);         frame.getcontentpane().add(menubar, borderlayout.north); } 

and current jframe:

current jframe

i trying figure out how move screenshot , settings buttons right side rather left located.

try this:

menubar.add(filemenu); menubar.add(box.createhorizontalglue()); menubar.add(screenshot); menubar.add(settings); 

as per java tutorial: how use menus / customizing menu layout


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -