Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » WindowBuilder » Wrong display of components.
Wrong display of components. [message #907172] Mon, 03 September 2012 12:57 Go to next message
kol kol is currently offline kol kolFriend
Messages: 5
Registered: September 2012
Junior Member
Hello.
Please tell me if this is a bug or intentional.

Structure of my GUI:
JPanel called "main" is added to JFrame called "application".
To JPanel "main" i've added JPanels "A" and "B".

I have such classes that describe JPanel "A" and some specific text field:
public class A extends JPanel
{
   private JTextField jtf;

   public A()
   {
       jtf = new JTextField();
       ...setting size and positions...
       add(jtf);
      
   }

   class VerySpecificJTF extends SpecificJTF 
   {
      public VerySpecificJTF (){}
   }
}

=========class in another file===============
abstract public class SpecificJTF extends JTextField
{
   ...some code...
}

}


As you see, there is an inner class VerySpecificJTF .
But now I just added standard JTextField to JPanel "A". All is ok. Text field is visible both when i use Design view directly on JPanel "A" and JForm "application".
BUT when i will use this code:

public class A extends JPanel
{
   private VerySpecificJTF jtf;

   public A()
   {
       jtf = new VerySpecificJTF();
       ...setting size and positions...
       add(jtf);
      
   }

   class VerySpecificJTF extends SpecificJTF 
   {
      public VerySpecificJTF (){}
   }
}

i dont see any VerySpecificJTF on JPanel "A" but i see it in Design view of JFrame "application". Is this proper behaviour?

[Updated on: Mon, 03 September 2012 12:58]

Report message to a moderator

Re: Wrong display of components. [message #907207 is a reply to message #907172] Mon, 03 September 2012 14:20 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
Yes, that is expected behavior.

Only proper Java Bean components can be used as editable widgets in the design view. VerySpecificJTF is not a valid Java Bean component.

In general, best practices dictate that all custom widget classes be public and contained in their own top-level classes (no inner classes).
Re: Wrong display of components. [message #907511 is a reply to message #907207] Tue, 04 September 2012 06:42 Go to previous messageGo to next message
kol kol is currently offline kol kolFriend
Messages: 5
Registered: September 2012
Junior Member
Do you think that this is proper way of handling components?
Inner class has this advantage that indicates that its used only in range of enclosing one.
Besides it can use methods of its container.
When i will export customized button to separate class i have to pass parent to this component and make some methods of this parent public. This is not "pretty" programming.
I have impression that WindowBuilder makes easier proccess of creation GUI but makes difficult to use some basic advantages of Java.
Is any way to change this default way of parsing code in WB?
Can you explain me why there are different visibilities on different levels?

[Updated on: Tue, 04 September 2012 06:50]

Report message to a moderator

Re: Wrong display of components. [message #907995 is a reply to message #907511] Tue, 04 September 2012 14:19 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
I believe that the standard and proper way to create and use custom components is for each to be in its own top-level, public class. All components should be Java Bean compliant as well.

We do not plan to support inner classes, non-public classes or non-Java Bean compliant classes as components. Doing so would definitely result in "not pretty programming" and encourage the use of non-standard UI practices.

If you have such extreme coupling between your UI components, you might want to revisit your overall design and add some better model/view separation. There should be no reason for parent and child UI components to access private state of the other.
Re: Wrong display of components. [message #908361 is a reply to message #907995] Wed, 05 September 2012 08:34 Go to previous messageGo to next message
kol kol is currently offline kol kolFriend
Messages: 5
Registered: September 2012
Junior Member
Thank you for information. This clarifies a situation.

Can you give me a hint how to solve this situation using WindowBuilder:
I want to create a pattern to prevent (eg accidentally) omiting some important components on JPanel. Simply speaking i want to have some checkBox that indicates if this panel should be available in particular situation or not.
I ensure this by using abstract class:

public abstract class PatternPanel extends JPanel
{
public JCheckBox isActive;
abstract void someMethod();
...
}


Because of all restrictions mentioned in previous posts application will be working, but design view will omit isActive element when i extend my new JPanel using SomePanel.


[Updated on: Wed, 05 September 2012 08:36]

Report message to a moderator

Re: Wrong display of components. [message #908750 is a reply to message #908361] Thu, 06 September 2012 00:13 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
I'm not sure what question you are asking. A complete example might be a good idea here.
Re: Wrong display of components. [message #908863 is a reply to message #908750] Thu, 06 September 2012 06:16 Go to previous messageGo to next message
kol kol is currently offline kol kolFriend
Messages: 5
Registered: September 2012
Junior Member
I would like to create JPanel pattern for enforce of using some components with every panel created by his extension.
Can you give me a hint how to solve this situation using WindowBuilder? "solve" means to do it in this way which will make possible components to be displayed by WindowBuilder.
I don't need a specific code but if you have any example how to do it, it would be great.

===== PatternPanel.java ================
public abstract class PatternPanel extends JPanel
{
public JCheckBox isActive;     //should be this panel active or not
abstract void someMethod();
}

===== SpecificPanel.java ================
public SpecificPanel extends PatternPanel 
{
//JCheckBox isActive = new JCheckBox();    //isActive will be showed but for me this is useless
public SpecificPanel()
{isActive = new JCheckBox();  //isActive will not be showed on SpecifecPanel in design view. How to do that design wiev will show this component?
isActive.setEnabled(true);
}

void someMethod(){};

[Updated on: Thu, 06 September 2012 06:17]

Report message to a moderator

Re: Wrong display of components. [message #909682 is a reply to message #908863] Fri, 07 September 2012 15:13 Go to previous messageGo to next message
Eric Clayberg is currently offline Eric ClaybergFriend
Messages: 979
Registered: July 2009
Location: Boston, MA
Senior Member
If you are trying to achieve some sort of visual inheritance, I would try something like this:

public abstract class PatternPanel extends JPanel {
	public JCheckBox isActive = new JCheckBox();
	public PatternPanel() {
		add(isActive);
	}
	abstract void someMethod();
}

public class SpecificPanel extends PatternPanel {
	public SpecificPanel() {
		isActive.setEnabled(true);
	}
	void someMethod() {
	};
}
Re: Wrong display of components. [message #910634 is a reply to message #909682] Mon, 10 September 2012 06:13 Go to previous message
kol kol is currently offline kol kolFriend
Messages: 5
Registered: September 2012
Junior Member
So obvious...
Thank you for help.
Previous Topic:Disambiguating wizards
Next Topic:WindowBuilder not behaving in Mountain Lion
Goto Forum:
  


Current Time: Thu Mar 28 08:26:51 GMT 2024

Powered by FUDForum. Page generated in 0.06482 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top