java - Can't get custom JPanel to show up on JDialog -


i have developed own properties type data structure setting basic data within application. using regular properties, wanted user able edit these , have notes, display order, , whether or not active. also, able group different properties.

i created panel displays property "edit" button them make changes.

then panel loads group , displays of properties group.

both of panels seem work fine. when create jdialog should load of groups panel each, can't display. have toyed lots of layouts , no luck. in addition, need scrollpane when grow overtime.

i not quite sure @ point...if add buttons panel, scrolls fine, assume wrong panel trying add.

here property group class:

import java.util.linkedhashmap;  public class smokepropertygroup { private string name = null; private string notes = null; private int displayorder = 0; private boolean active = true; private linkedhashmap<string, smokeproperty> properties = new linkedhashmap<>();  public smokepropertygroup(string name, string notes, int displayorder, boolean active) {     super();     this.name = name;     this.notes = notes;     this.displayorder = displayorder;     this.active = active; }  public string getname() {     return name; }  public void setname(string name) {     this.name = name; }  public string getnotes() {     return notes; }  public void setnotes(string notes) {     this.notes = notes; }  public int getdisplayorder() {     return displayorder; }  public void setdisplayorder(int displayorder) {     this.displayorder = displayorder; }  public boolean isactive() {     return active; }  public void setactive(boolean active) {     this.active = active; }  public linkedhashmap<string, smokeproperty> getproperties() {     return properties; }  public void addproperties(smokeproperty property) {     this.properties.put(property.getname(), property); }  } 

here actual property class:

public class smokeproperty { private string groupname = null; private string name = null; private string value = null; private string notes = null; private int displayorder = 0; private boolean active = true; private string displayablename = null;  public smokeproperty(string groupname, string name, string value, string notes, int displayorder, boolean active) {     super();     this.groupname = groupname;     this.name = name;     this.value = value;     this.notes = notes;     this.displayorder = displayorder;     this.active = active; }  public string getgroupname() {     return groupname; }  public void setgroupname(string groupname) {     this.groupname = groupname; }  public string getname() {     return name; }  public string getdisplayablename() {     return name;  }  public void setname(string name) {     this.name = name; }  public string getvalue() {     return value; }  public void setvalue(string value) {     this.value = value; }  public string getnotes() {     return notes; }  public void setnotes(string notes) {     this.notes = notes; }  public int getdisplayorder() {     return displayorder; }  public void setdisplayorder(int displayorder) {     this.displayorder = displayorder; }  public boolean isactive() {     return active; }  public void setactive(boolean active) {     this.active = active; }  @override public string tostring() {     return "smokeproperty \n" + "  groupname=" + groupname + "\ndisplayablename=" + getdisplayablename() + "\nname="             + name + "\nvalue=" + value + "\nnotes=" + notes + "\ndisplayorder=" + displayorder + "\nactive="             + active + "\n\n"; }  } 

here panel displays property:

import java.awt.font; import java.awt.gridbagconstraints; import java.awt.gridbaglayout; import java.awt.insets;  import javax.swing.jbutton; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.swingconstants;  public class panelsmokeproperty extends jpanel {  private jlabel lblname = new jlabel();  public panelsmokeproperty(smokeproperty prop) {     gridbaglayout gridbaglayout = new gridbaglayout();     gridbaglayout.columnwidths = new int[] { 318, 567, 97, 0 };     gridbaglayout.rowheights = new int[] { 25, 0 };     gridbaglayout.columnweights = new double[] { 0.0, 0.0, 0.0, double.min_value };     gridbaglayout.rowweights = new double[] { 0.0, double.min_value };     setlayout(gridbaglayout);      jbutton btnedit = new jbutton("edit");      lblname.sethorizontalalignment(swingconstants.right);     lblname.setfont(new font("tahoma", font.plain, 13));     gridbagconstraints gbc_lblname = new gridbagconstraints();     gbc_lblname.weighty = 0.4;     gbc_lblname.weightx = 0.4;     gbc_lblname.fill = gridbagconstraints.horizontal;     gbc_lblname.insets = new insets(0, 0, 0, 5);     gbc_lblname.gridx = 0;     gbc_lblname.gridy = 0;     this.add(lblname, gbc_lblname);      lblname.settext(prop.getname() + " = ");      jlabel lblvalue = new jlabel(prop.getvalue());     gridbagconstraints gbc_lblvalue = new gridbagconstraints();     gbc_lblvalue.weighty = 0.4;     gbc_lblvalue.weightx = 0.4;     gbc_lblvalue.fill = gridbagconstraints.horizontal;     gbc_lblvalue.insets = new insets(0, 0, 0, 5);     gbc_lblvalue.gridx = 1;     gbc_lblvalue.gridy = 0;     add(lblvalue, gbc_lblvalue);     gridbagconstraints gbc_btnedit = new gridbagconstraints();     gbc_btnedit.weighty = 0.2;     gbc_btnedit.weightx = 0.2;     gbc_btnedit.anchor = gridbagconstraints.north;     gbc_btnedit.fill = gridbagconstraints.both;     gbc_btnedit.gridx = 2;     gbc_btnedit.gridy = 0;     add(btnedit, gbc_btnedit); } } 

here panel show property group:

import java.awt.dimension; import java.awt.gridbagconstraints; import java.awt.gridbaglayout; import java.awt.insets;  import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.swingconstants; import javax.swing.border.titledborder;  public class panelsmokepropertygroup extends jpanel {  public panelsmokepropertygroup(smokepropertygroup propgroup) {      this.setborder(new titledborder(null, propgroup.getname(), titledborder.leading, titledborder.top, null, null));     gridbaglayout gridbaglayout = new gridbaglayout();     gridbaglayout.columnwidths = new int[] { 1133, 0 };     gridbaglayout.rowheights = new int[] { 100, 176, 0 };     gridbaglayout.columnweights = new double[] { 1.0, double.min_value };     gridbaglayout.rowweights = new double[] { 0.0, 0.0, double.min_value };     setlayout(gridbaglayout);      jlabel lbllabelfordescription = new jlabel("label description");     lbllabelfordescription.setpreferredsize(new dimension(100, 75));     lbllabelfordescription.setverticalalignment(swingconstants.top);     gridbagconstraints gbc_lbllabelfordescription = new gridbagconstraints();     gbc_lbllabelfordescription.anchor = gridbagconstraints.north;     gbc_lbllabelfordescription.fill = gridbagconstraints.horizontal;     gbc_lbllabelfordescription.insets = new insets(0, 0, 5, 0);     gbc_lbllabelfordescription.gridx = 0;     gbc_lbllabelfordescription.gridy = 0;     this.add(lbllabelfordescription, gbc_lbllabelfordescription);      jpanel panelforproperties = new jpanel();     gridbagconstraints gbc_panelforproperties = new gridbagconstraints();     gbc_panelforproperties.weighty = 1.0;     gbc_panelforproperties.weightx = 1.0;     gbc_panelforproperties.gridx = 0;     gbc_panelforproperties.gridy = 1;     add(panelforproperties, gbc_panelforproperties);     gridbaglayout gbl_panelforproperties = new gridbaglayout();     gbl_panelforproperties.columnwidths = new int[] { 0, 0 };     gbl_panelforproperties.rowheights = new int[] { 0, 0 };     gbl_panelforproperties.columnweights = new double[] { 1.0, double.min_value };     gbl_panelforproperties.rowweights = new double[] { 0.0, double.min_value };     panelforproperties.setlayout(gbl_panelforproperties);      gridbagconstraints gbc_panelproperty = new gridbagconstraints();     gbc_panelproperty.fill = gridbagconstraints.horizontal;     gbc_panelproperty.gridx = 0;     // int scrollpaneheight = (int) scrollpane.getbounds().getheight();     // panelforproperties.setpreferredsize(new dimension(749,     // scrollpaneheight));     int y = 0;     (smokeproperty p : propgroup.getproperties().values()) {         panelsmokeproperty panelpropery = new panelsmokeproperty(p);         gbc_panelproperty.gridy = y++;         panelforproperties.add(panelpropery, gbc_panelproperty);     }  }  public static void main(string... args) {     jframe frame = new jframe("test");     frame.setpreferredsize(new dimension(700, 700));     panelsmokepropertygroup panel = new panelsmokepropertygroup(dialogproperties.getgroups().get("group 1"));     // panelsmokepropertygroup2 panel2 = new     // panelsmokepropertygroup2(dialogproperties.getgroups().get("group     // 2"));     frame.getcontentpane().add(panel);     // frame.getcontentpane().add(panel2);      frame.setvisible(true); } } 

and finally, here jdialog uses , won't show panels properly:

import java.awt.gridbagconstraints; import java.awt.gridbaglayout; import java.awt.gridlayout; import java.awt.insets; import java.util.linkedhashmap;  import javax.swing.jbutton; import javax.swing.jdialog; import javax.swing.jpanel; import javax.swing.jscrollpane; import javax.swing.border.emptyborder;  public class dialogproperties extends jdialog {  private final jpanel contentpanel = new jpanel();  public static void main(string[] args) {     try {         dialogproperties dn = new dialogproperties();         dn.setdefaultcloseoperation(jdialog.dispose_on_close);         dn.setvisible(true);     } catch (exception e) {         e.printstacktrace();     } }  public dialogproperties() {      this.setdefaultcloseoperation(jdialog.dispose_on_close);      settitle("system properties");     setmodal(true);     setbounds(100, 100, 869, 608);     gridbaglayout gridbaglayout = new gridbaglayout();     gridbaglayout.columnwidths = new int[] { 851, 0 };     gridbaglayout.rowheights = new int[] { 561, 0 };     gridbaglayout.columnweights = new double[] { 0.0, double.min_value };     gridbaglayout.rowweights = new double[] { 0.0, double.min_value };     getcontentpane().setlayout(gridbaglayout);     contentpanel.setborder(new emptyborder(5, 5, 5, 5));     gridbagconstraints gbc_contentpanel = new gridbagconstraints();     gbc_contentpanel.fill = gridbagconstraints.both;     gbc_contentpanel.gridx = 0;     gbc_contentpanel.gridy = 0;     getcontentpane().add(contentpanel, gbc_contentpanel);     gridbaglayout gbl_contentpanel = new gridbaglayout();     gbl_contentpanel.columnwidths = new int[] { 1, 800, 0 };     gbl_contentpanel.rowheights = new int[] { 477, 50, 0 };     gbl_contentpanel.columnweights = new double[] { 0.0, 0.0, double.min_value };     gbl_contentpanel.rowweights = new double[] { 0.0, 0.0, double.min_value };     contentpanel.setlayout(gbl_contentpanel);      jscrollpane scrollpane = new jscrollpane();     // scrollpane.setbounds(12, 13, 1235, 382);     gridbagconstraints gbc_scrollpane = new gridbagconstraints();     gbc_scrollpane.gridwidth = 2;     gbc_scrollpane.fill = gridbagconstraints.both;     gbc_scrollpane.insets = new insets(0, 0, 5, 0);     gbc_scrollpane.gridx = 0;     gbc_scrollpane.gridy = 0;     contentpanel.add(scrollpane, gbc_scrollpane);      jpanel panel = new jpanel();     scrollpane.setviewportview(panel);     panel.setlayout(new gridlayout(0, 1));     jbutton okbutton = new jbutton("ok");     gridbagconstraints gbc_okbutton = new gridbagconstraints();     gbc_okbutton.ipady = 45;     gbc_okbutton.ipadx = 45;     gbc_okbutton.anchor = gridbagconstraints.southeast;     gbc_okbutton.gridx = 1;     gbc_okbutton.gridy = 1;     contentpanel.add(okbutton, gbc_okbutton);      okbutton.setactioncommand("ok");     getrootpane().setdefaultbutton(okbutton);      (smokepropertygroup group : getgroups().values()) {         panelsmokepropertygroup p = new panelsmokepropertygroup(group);         panel.add(p);     }  }  public static linkedhashmap<string, smokepropertygroup> getgroups() {     linkedhashmap<string, smokepropertygroup> groups = new linkedhashmap<>();      (int = 1; <= 10; i++) {         smokepropertygroup g1 = new smokepropertygroup("group " + i, "some notes", 0, true);         (int p = 1; p <= 15; p++) {             g1.addproperties(new smokeproperty(g1.getname(), "property " + p, "something", "notes", 0, true));         }         groups.put(g1.getname(), g1);     }     return groups; } } 


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -