swing - Java GUI, organizing a dialog box to get data from the user -
i designing gui research project. want create dialog box gets information user. here screenshot:
here code screenshot above:
jtextfield projnamefield = new jtextfield(10); jtextfield nfield = new jtextfield(5); jtextfield mfield = new jtextfield(5); jtextfield alphafield = new jtextfield(5); jtextfield kfield = new jtextfield(5); jfilechooser inputfile = new jfilechooser(); inputfile.setfileselectionmode(jfilechooser.files_and_directories); file file = inputfile.getselectedfile(); string fullpath = file.getabsolutepath(); jpanel mypanel = new jpanel(); mypanel.add(new jlabel("project name:")); mypanel.add(projnamefield); mypanel.add(new jlabel("number of instances:")); mypanel.add(nfield); mypanel.add(new jlabel("number of attributes:")); mypanel.add(mfield); mypanel.add(new jlabel("alpha:")); mypanel.add(alphafield); mypanel.add(new jlabel("number of patterns:")); mypanel.add(kfield); mypanel.add(new jlabel("please select datset:")); mypanel.add(inputfile); mypanel.setlayout(new boxlayout(mypanel, boxlayout.y_axis)); int result = joptionpane.showconfirmdialog( null, mypanel, "cpm program", joptionpane.ok_cancel_option); double alpha = double.parsedouble(alphafield.gettext()); int numpat = integer.parseint(kfield.gettext()); int num_inst = integer.parseint(nfield.gettext()); int num_attr = integer.parseint(mfield.gettext()); string projname = (projnamefield.gettext());
in reference above image have 2 questions:
notice labels centered. how can put in left side this:
project name: --textbox-- number of instances: --textbox--
in label, "please select dataset", want browse file, select , copy full path in blank box in front of "please select dataset" label, not know how should it.
1- first problem of labels such project name or number of instances centered (it seems!). how can put in left side?
jlabel has constructor takes int 1 of parameters, , can use position text held in jlabel.
2- second problem text fields not in front of labels , below of them. want have each text field in front of label such as:
layouts key here. consider using gridbaglayout (which can difficult use initially) or miglayout (easier use have download first) allow use of more tabular structure gui.
for example, please have @ code in this answer example of tabular structure using gridbaglayout.
Comments
Post a Comment