Custom initialization code for components?

Hello all. Is there any way to define custom initialization code for components? I'd like to not use the default constructor for JTree since it populates the tree with garbage data, but I can't seem to get around the UI Designer re-assigning the variable. For example, if I have:


this behavior is overridden in the UI Designer's init method. It seems that I then have to manually remove the sample data from the tree node which is both inefficient and a pain in the ^$$. I'd like to be able to specify the initialization / constructor behavior for components that are added to my form. Is this possible? Thanks so much.

0
8 comments
Avatar
Permanently deleted user

Hello!
Please, see "Using swing components subclasses without palette" discussion.

We already discuss it...

"jeff" <no_reply@jetbrains.com> wrote in message
news:12010157.1075684277729.JavaMail.itn@is.intellij.net...

Hello all. Is there any way to define custom initialization code for

components? I'd like to not use the default constructor for JTree since
it populates the tree with garbage data, but I can't seem to get around the
UI Designer re-assigning the variable. For example, if I have:
>

 private JTree myTree = new JTree(new DefaultMutableTreeNode("root node
name"));
> ]]>

>

this behavior is overridden in the UI Designer's init method. It seems

that I then have to manually remove the sample data from the tree node which
is both inefficient and a pain in the ^$$. I'd like to be able to specify
the initialization / constructor behavior for components that are added to
my form. Is this possible? Thanks so much.


0
Avatar
Permanently deleted user

I've read that discussion which does not seem to provide a solution. Instead, it discusses two different possible solutions for fixing this problem. AFAIK, the UI-Designer's init method does not check for null and will always override the construction of an component object. What is the way around this? Thanks!

0
Avatar
Permanently deleted user

BTW - when I say possible solutions, I mean possible solutions from the JetBrains team, not things that we as users can do.

0
Avatar
Permanently deleted user

Doesn anyone from JetBrains have any comments on this? It's ridiculous that there's no easy way to define the constructor for an object. The default constructor is the only one that's used which prevents using constructors that take data or easily using a subclass. If I'm developing a subclass of a component, I can't compile, add it to a custom palette, and restart IDEA every time I make a change. There's got to be an easier way to define custom initialization code. If possible, at least let the user specify a subclass in the UI-Designer. If I have a JTree form in my UI Designer I should be able to bind it to a subclass of JTree without having to add a custom palette.

0
Avatar
Permanently deleted user

I'm facing the same issue, so I'd like to bump this thread since no one from Jetbrains seems to have replied to it.

I'm a business logic/back-end developer trying to get a batter handle on GUI development by trying to use it. I was greatly encouraged by the IDEA GUI developer.

But, for some swing components its common to make a new subclass for each use (e.g. JTree). Unfortunately in the IDEA GUI editor this requires either creating a custom XML descriptor or clearing out the base class default nodes. Neither is a particullarly good situation for these one-off instances.

Anyone from JetBrains care to comment? Is this fixed in 4.5?


0
Avatar
Permanently deleted user

Aaron Tavistock wrote:

But, for some swing components its common to make a new subclass for
each use (e.g. JTree). Unfortunately in the IDEA GUI editor this
requires either creating a custom XML descriptor or clearing out the
base class default nodes. Neither is a particullarly good situation
for these one-off instances.


Why make subclasses of Jtree? Surely you'd just use the standard JTree
but provide a custom TreeModel object?

As for editing the XML - you can now edit the component pallette from
the UI Designer settings under your project configs.

--
Discouragement is a dissatisfaction with the past, a distaste for the
present, and a distrust of the future - Maree De Jong, CLCA.

Mark Derricutt --- mark@ talios.com --- http://www.talios.com

0

I think you have the right code, but are putting it in the wrong place. Here is what worked for me:

  1. In the designer, select properties for your tree.
  2. Check the Custom Create Checkbox
  3. Press F4 or right-click and select Jump to Source
  4. Place your code in the createUIComponents() method which was generated when you clicked Custom Create
  5. Note:  you must instantiate all components for which you checked Custom Create in this method.  Otherwise you will get a null pointer exception.


Hope this helps.

0

I think you have the right code, but are putting it in the wrong place. Here is what worked for me:

  1. In the designer, select properties for your tree.
  2. Check the Custom Create Checkbox
  3. Press F4 or right-click and select Jump to Source
  4. Place your code in the createUIComponents() method which was generated when you clicked Custom Create
  5. Note:  you must instantiate all components for which you checked Custom Create in this method.  Otherwise you will get a null pointer exception.


Hope this helps.

[sorry for the double post.  I originally clicked the wrong hyperlink, and there does not appear to be an option for deleting a post]

0

Please sign in to leave a comment.