• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Gajesh Tripathi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
[Thumbnail for PnlForQuery.java.jpg]
PnlForQuery: A Java Bean Component (extension: java)
PnlForQuery.form.jpg
[Thumbnail for PnlForQuery.form.jpg]
A GUI form file created using Netbeans IDE (extension: form)
PnlForQueryBeanInfo.java.jpg
[Thumbnail for PnlForQueryBeanInfo.java.jpg]
BeanInfo file of PnlForQuery (extension: java)
 
Gajesh Tripathi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gajesh,
Glad it was of help to you.

And thanks for posting back a better solution.
 
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic