2

I am designing some custom graphical components using Netbeans 7.4. I am making some smaller components that combine to make larger custom components. However, when I change one of the bottom-level components, the changes do not propagate up to other elements.

Is there any way to insert a custom component so that changes to it's base percolate to all the instances? Somewhat new to fiddling with Swing, so my apologies if this is a trivial thing.

I have already added them to a custom palette hoping that would do something, but alas to no avail.

Aaron Marcus
  • 153
  • 2
  • 13

1 Answers1

2

The NetBeans GUI designer doesn't support this directly, but you can instantiate your own custom components as often as desired. The key is designing for reuse. I try to follow the Swing separable model architecture, even if there's no need for a custom look & feel.

Edit: I added two instances of NewJPanel to Main like in this example. When I changed the label's text in the designer, it changed in both panels at runtime.

f.setLayout(new GridLayout(0, 1));
f.add(new NewJPanel());
f.add(new NewJPanel());
Community
  • 1
  • 1
Catalina Island
  • 7,027
  • 2
  • 23
  • 42
  • So to be bluntly clear, in a situation where you design an element and use it in multiple places, but then change it, you simply have to delete and re-add the component in all the places it was used? – Aaron Marcus Mar 11 '14 at 18:39
  • I'm not sure I understand why you'd have to delete anything. You can reuse a panel like they show [here](http://stackoverflow.com/a/2561540/261156). Any changes to the properties, including code properties, get regenerated for each instance when you build the project. – Catalina Island Mar 13 '14 at 10:51
  • Sorry for the misunderstanding, I am referring to graphical elements. Not code changes, code changes do propagate. But if I move a button around on the original, it doesn't seem to update the location of the button in places where I use that object – Aaron Marcus Mar 13 '14 at 19:32
  • Sorry, I'm not seeing the problem. I added the example I tried. – Catalina Island Mar 14 '14 at 12:55
  • I'm talking about the layout, spacing of elements for example. If you have a panel that has a label in it, and you move the label, it does not percolate to all the places that panel is used. You need to delete it and re-add the panel. – Aaron Marcus Mar 17 '14 at 18:11
  • 1
    Right, if you paste a copy in the designer, but not if you instantiate the class and add it to a container. – Catalina Island Mar 18 '14 at 11:54
  • Agreed. But the physical graphical layout necessitates copying and pasting, that is the extra step I was curious if I could avoid. It's slightly annoying if you fix auto-spacing shenanigans only to make a subtle tweak and have to re-adjust the spacing all over again – Aaron Marcus Mar 18 '14 at 15:23