user interface - How do I get my JTextFields to line up correctly under a title? -



user interface - How do I get my JTextFields to line up correctly under a title? -

this should like

import java.awt.*; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.*; public class ui extends jframe { private static final long serialversionuid = 1l; private jpanel toppanel; private jpanel mainpanel; private jpanel botpanel; private jlabel message; private jtextfield total, total1, total2, total3, total4, total5; private jtextfield score, score1, score2, score3, score4,score5; private final int width = 650; private final int height = 400; public ui() { settitle("desert soccer league"); setsize(width,height); setdefaultcloseoperation(jframe.exit_on_close); buildtop(); add(toppanel, borderlayout.north); buildmain(); add(mainpanel, borderlayout.center); buildbot(); add(botpanel, borderlayout.south); } private void buildtop() { toppanel = new jpanel(new flowlayout()); message = new jlabel("2014 desert soccer league"); toppanel.add(message); } private void buildmain() { mainpanel = new jpanel(new flowlayout(0,100,20)); jlabel team = new jlabel("teams"); jlabel points = new jlabel("total points"); jlabel winloss = new jlabel("win-loss-tie"); jtextfield t = new jtextfield(10); t.settext("arabian"); t.setenabled(false); jtextfield t1 = new jtextfield(10); t1.settext("gobi"); t1.setenabled(false); jtextfield t2 = new jtextfield(10); t2.settext("outback"); t2.setenabled(false); jtextfield t3 = new jtextfield(10); t3.settext("patagonian"); t3.setenabled(false); jtextfield t4 = new jtextfield(10); t4.settext("sahara"); t4.setenabled(false); jtextfield t5 = new jtextfield(10); t5.settext("sonoran"); t5.setenabled(false); mainpanel.add(team); mainpanel.add(points); mainpanel.add(winloss); mainpanel.add(t); mainpanel.add(t1); mainpanel.add(t2); mainpanel.add(t3); mainpanel.add(t4); mainpanel.add(t5); } private void buildbot() { botpanel = new jpanel(new flowlayout()); jbutton io = new jbutton("read input file"); io.setactioncommand("i"); io.addactionlistener(new buttonlistener()); jbutton calc = new jbutton("calculate points"); calc.setactioncommand("c"); calc.addactionlistener(new buttonlistener()); jbutton champ = new jbutton("championship winner"); champ.setactioncommand("o"); champ.addactionlistener(new buttonlistener()); jbutton sec = new jbutton("earth cup wiiner"); second.setactioncommand("t"); second.addactionlistener(new buttonlistener()); jbutton exit = new jbutton("exit"); exit.setactioncommand("e"); exit.addactionlistener(new buttonlistener5()); botpanel.add(io); botpanel.add(calc); botpanel.add(champ); botpanel.add(second); botpanel.add(exit); } private class buttonlistener implements actionlistener { public void actionperformed(actionevent e) { if(e.getactioncommand() == "i") { joptionpane.showinputdialog("enter path , name of file"); } } } private class buttonlistener5 implements actionlistener { public void actionperformed(actionevent e) { if(e.getactioncommand() == "e") { system.exit(0); } } } public static void main(string[] args) { ui frame = new ui(); frame.setvisible(true); } }

i'm having problem lining textfileds under jlabel teams. can help me line first row of text fields illustration above. i've tried gridlayout doesn't seem work way , since resizes automatically looks unappealing. because class project can utilize have been taught layouts have learned borderlayout, flowlayout, , gridlayout. help appreciated.

put labels in grid, not in separate panel above grid.

user-interface jpanel jtextfield flowlayout

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -