java - Programatically Create and Select Values From Components - Swing -
java - Programatically Create and Select Values From Components - Swing -
i've got method adds instructions, button , jlabel jpanel on click need way of selecting these 3 elements can style them, i'm using solution of iterating through components , finding ones want style won't allow me set border of jpanels, it's not alternative when view available methods. there anyway set border of jlabel in loop @ bottom? or way individually select each element.
when user clicks button on different jpanel generateimagearea method runs.
public void generateimagearea(int id) { areaheight += 200; // extends jpanel i++; gbc.gridx = 0; gbc.gridy = i; gbc.gridwidth = 4; gbc.anchor = gridbagconstraints.line_start; // add together instructions jlabel add(new jlabel("["+ (id+5) + "]: select image of maximum dimensions 720 * 350 pixels."), gbc); i++; gbc.gridx = 0; gbc.gridy = i; gbc.gridwidth = 1; gbc.anchor = gridbagconstraints.line_start; // add together button load image add(new jbutton("load image")); gbc.gridx = 1; gbc.gridwidth = 3; // add together jlabel acts space display image add(new jlabel("")); // set colour + font of instructions jlabel (int = 0; < this.getcomponentcount(); i++) { component comp = this.getcomponent(i); if (comp.tostring().contains("]:")) { comp.setforeground(settings.site_green); comp.setfont(settings.subtitlefont); } else if (comp.tostring().contains("")) { // need alter border of sec jlabel } } } similar need programatically add together jtextareas style , retrieve info them after user clicks submit. how can programatically add together components able extract input afterwards?
instead of finding elements want style, can style them directly. example, instead of doing this:
add(new jlabel("["+ (id+5) + "]: select image of maximum dimensions 720 * 350 pixels."), gbc); you can do:
// create instruction label jlabel instruction = new jlabel("["+ (id+5) + "]: select image of maximum dimensions 720 * 350 pixels."); // style instruction.setforeground(settings.site_green); instruction.setfont(settings.subtitlefont); // add together it. add(instruction, gbc); i believe approach easier, , less error prone.
java swing
Comments
Post a Comment