aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to use ComboBox as PropertyEditor for Property of Java Bean Component? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to use ComboBox as PropertyEditor for Property of Java Bean Component?" Watch "How to use ComboBox as PropertyEditor for Property of Java Bean Component?" New topic
Author

How to use ComboBox as PropertyEditor for Property of Java Bean Component?

Gajesh Tripathi
Greenhorn

Joined: Jul 06, 2006
Posts: 9
I created a Java Bean component named as "PnlForQuery" that has a property named "database":-

/*Default value for this property is "ORACLE" but It can be: "MS-ACCESS", "SQL-SERVER", "MYSQL",....etc.*/
String database = "ORACLE";


How can I create a comboBox editor for this property to accept one of above string values for database so that I can use it using Beanbox provided by Netbeans or any other IDE ?

If we need to use PropertyEditor class for this purpose then plese give me an example...

Thanks In Advance
GAJESH
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1089
    
  10

Hi Gajesh,
Welcome to the Ranch!

There is a class PropertyEditorSupport present in the java.beans package. You need to extend it and override the getCustomEditor() method to return your own component (also I think the supportsCustomEditor() method must also be overridden). You should start from there.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Gajesh Tripathi
Greenhorn

Joined: Jul 06, 2006
Posts: 9
Ranganathan Kaliyur Mannar wrote:Hi Gajesh,
Welcome to the Ranch!

There is a class PropertyEditorSupport present in the java.beans package. You need to extend it and override the getCustomEditor() method to return your own component (also I think the supportsCustomEditor() method must also be overridden). You should start from there.


Thank you Mr. Ranganathan Kaliyur Mannar for your reply..

I created a class DatabaseEditor as suggested by you...

Other source codes are attached herewith: Due to limitation of coderanch, I use .jpg extension with actual file, please remove .jpg extension to use these attachment files

But its not working, please check my code & tell me what & where is actual problem?

Purpose of my java bean component is : fill list using "connection", "tableName", "keyFieldName" & "valueFieldName" property & also generate condition that can be used in another sql query according to user's selection. You can also import this code into your test/sample netbean project for checking purpose.

I register this property using following fragment of code:-



[PnlForQuery.java.jpg]


[PnlForQuery.form.jpg]


[PnlForQueryBeanInfo.java.jpg]

Gajesh Tripathi
Greenhorn

Joined: Jul 06, 2006
Posts: 9
When I use this property DatabaseEditor.class then comboBox is showing but when changing value from combo then following error is showing:-
java.lang.IllegalArgumentException: argument type mismatch

Please check my DatabaseEditor class & tell me why this error is occurred if you know about that.

Any ways, my main problem is solved & its my duty to submit solution here for closing this Thread.
Modification in PnlForQuery.java

Modification in PnlForQueryBeanInfo.java

and its successfully working.[/code]

Advantage of This Thread:-How to use combo box as a Property Editor? and conclusion is that we do not require to extend PropertyEditorSupport for selecting one value from multiple choice. Instead we set the multiple choice values to enumerationValues attribute of PropertyDescriptor's object.

Thanks for viewing this Thread...
GAJESH
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1089
    
  10

Hi Gajesh,
Glad it was of help to you.

And thanks for posting back a better solution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use ComboBox as PropertyEditor for Property of Java Bean Component?