fields of costum components in inspector?

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

fields of costum components in inspector?

Postby dulcet » Thu Aug 03, 2006 6:54 am

Hi,

I'm new to Java, Eclipse and the Designer Editor.
I use a class MyTextField that extends JTextFields that lets me set the maxLength and allowedChars of that TextField.

I can create it like this:
Code: Select all
txtFoo = new MyTextField(100,CHAR_ALL);
// user can enter up to 100 characters


or I could do this:
Code: Select all
// user can enter up to 30 characters (a-Z0-9-_.@)
txtFoo = new MyTextField();
txtFoo.setMaxLength(30);
txtFoo.setAllowedChars(CHAR_EMAIL);


I have two problems:

1: I can choose the maxLength in the inspector and it will use the setter (setMaxLength). That's great. But when I set it in the sourcecode using the constructor it will not be recognized by the designer. It sometimes mistakes it for the property columns. Why is that so? Other components like JTextField can be created with arguments (e.g. the text) that will be recognized by the designer. How can I tell the designer what will be set by the constructor?

2: Since allowedChars is a String I'd like to use constants (see above) but they can not be selected using the inspector. But it often is possible to choose from constants, e.g. when selecting a color.

Claude
dulcet
 
Posts: 1
Joined: Thu Aug 03, 2006 6:31 am
Location: Switzerland

Re: fields of costum components in inspector?

Postby Eric Clayberg » Mon Aug 07, 2006 7:32 pm

dulcet wrote:1: I can choose the maxLength in the inspector and it will use the setter (setMaxLength). That's great. But when I set it in the sourcecode using the constructor it will not be recognized by the designer. It sometimes mistakes it for the property columns. Why is that so? Other components like JTextField can be created with arguments (e.g. the text) that will be recognized by the designer. How can I tell the designer what will be set by the constructor?

Designer does not understand your special constructor syntax for MyTextField as it does not conform to normal bean info usage. Designer has special built-in knowledge of JTextField and its non-standard constructors because that widget is built into Swing. Note that while Designer can understand that code, it does not generate code in that style.

dulcet wrote:2: Since allowedChars is a String I'd like to use constants (see above) but they can not be selected using the inspector. But it often is possible to choose from constants, e.g. when selecting a color.

You would need to define your own bean info for the class and set up your own custom cell editors. Designer understands standard bean info, so you can define cell editors, widget customers, etc. See the Swing bean info spec for details.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest