Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Cannot change inherited controls(A child panel cannot change inherited (protected or public) widgets.)
Cannot change inherited controls [message #1062484] Fri, 07 June 2013 23:23 Go to next message
Thiago DP is currently offline Thiago DP
Messages: 4
Registered: June 2013
Junior Member
I created a panel (using JGoodies Form Layout) and the child class cannot add other widgets to it. When I try to add the widget manually (by code), WindowBuilder raises a NullPointerException. Please take a look in the attached file.
Re: Cannot change inherited controls [message #1062559 is a reply to message #1062484] Sat, 08 June 2013 20:55 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric Clayberg
Messages: 832
Registered: July 2009
Location: Boston, MA
Senior Member
Actually, the exception is being raised by the FormLayout itself (not by WindowBuilder) because the example code is violating a constraint. The example code throws the following exception:

java.lang.IndexOutOfBoundsException: The column index 7 must be less than or equal to 5.
at com.jgoodies.forms.layout.CellConstraints.ensureValidGridBounds(CellConstraints.java:935)
at com.jgoodies.forms.layout.FormLayout.setConstraints(FormLayout.java:826)
at com.jgoodies.forms.layout.FormLayout.addLayoutComponent(FormLayout.java:1103)

It appears you are trying to add a widget to the 7th column of a 5 column grid. That won't work. You can add inherited controls, but they can't violate the column spec defined in the parent. If I add an extra column to the parent class in your example, it then works fine whether I add the widget manually or through the editor.

[Updated on: Sat, 08 June 2013 20:55]

Report message to a moderator

Re: Cannot change inherited controls [message #1062562 is a reply to message #1062559] Sat, 08 June 2013 21:18 Go to previous messageGo to next message
Thiago DP is currently offline Thiago DP
Messages: 4
Registered: June 2013
Junior Member
OK. Many thanks, Eric. It is strange because when I try to add a component (like a button), it can't be placed in the parent's cell. I thought I could add columns/rows and add new components in the child class, like I used to do in other GUI frameworks, like Borland ones. So it is a constraint, right? Swing behaves a little bit different than I thought...

[Updated on: Sat, 08 June 2013 21:25]

Report message to a moderator

Re: Cannot change inherited controls [message #1062563 is a reply to message #1062562] Sat, 08 June 2013 21:36 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric Clayberg
Messages: 832
Registered: July 2009
Location: Boston, MA
Senior Member
You can add children in the child, but they have to be placed in a cell defined in the parent. If the parent class defines a 5x1 grid, you won't be able to add a widget at the 7x1 location. Enlarging the gird in the parent will allow you to add the extra widget in the child. This is a JGFL issue rather than a generic Swing issue. The grid is defined in the parent, so the constraint is set there.
Re: Cannot change inherited controls [message #1062564 is a reply to message #1062563] Sat, 08 June 2013 21:54 Go to previous messageGo to next message
Thiago DP is currently offline Thiago DP
Messages: 4
Registered: June 2013
Junior Member
I also can't add new columns/rows in the child, right? (I need to define everything in the parent).

WindowBuilder shows a "java.lang.ClassCastException: org.eclipse.wb.internal.swing.model.layout.ImplicitLayoutCreationSupport cannot be cast to org.eclipse.wb.internal.core.model.creation.ConstructorCreationSupport"
message when I try to do this.

Maybe it would be better (if possible) show better messages depending on the context. Just to make it easier to understand.

Thank you.


[Updated on: Sat, 08 June 2013 22:04]

Report message to a moderator

Re: Cannot change inherited controls [message #1062583 is a reply to message #1062564] Sun, 09 June 2013 08:31 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric Clayberg
Messages: 832
Registered: July 2009
Location: Boston, MA
Senior Member
Right. You can't alter the constraints set up in the parent. You need to define the number of rows and columns that you need in the parent and then you can add widgets to that grid in the child.

For what you are doing, GridBagLayout would be a much, much better choice. In that layout, the grid is built p implicitly based on where you place the children, so you can easily add new widgets pretty much anywhere you like.

For creating a row of buttons in the parent and then adding extra buttons in the child, the standard Swing GridLayout would also be a better choice.
Re: Cannot change inherited controls [message #1062603 is a reply to message #1062583] Sun, 09 June 2013 17:14 Go to previous message
Thiago DP is currently offline Thiago DP
Messages: 4
Registered: June 2013
Junior Member
Good point. I'll follow your suggestions. Thanks, Eric.
Previous Topic:GEF Components
Next Topic:XML databinding in SWT help
Goto Forum:
  


Current Time: Sat Apr 19 16:12:09 EDT 2014

Powered by FUDForum. Page generated in 0.05371 seconds