How to display the NetBeans font chooser.

Since I have been going after some low hanging fruits in fixing some Python support related issues in NetBeans, strictly over weekends (without the knowledge of my wife who prefers my MacBook Pro being 2000 miles away from me on weekends), I ran into an interesting issue where I had to display the NetBeans font chooser instead of a custom font chooser being used in the code. Unable to find the proper API (perhaps I am dumb), I waded into the NetBeans sources, and found the way out. Blogging about this here to save some poor soul some time when the need arises.

PropertyEditor pe = PropertyEditorManager.findEditor (Font.class);
DialogDescriptor dd = new DialogDescriptor (
    pe.getCustomEditor(),
    "Some Title"  // NOI18N
);

DialogDisplayer.getDefault ().createDialog (dd).setVisible (true);
if (dd.getValue () == DialogDescriptor.OK_OPTION) {
    font = (Font) pe.getValue ();
}

It just boils down to getting a property editor for Font and then wrapping the panel inside a dialog box using the NetBeans DialogDisplayer API.


Comments:

Interesting Tip.

Posted by Tushar Joshi on July 25, 2009 at 03:54 PM PDT #

Post a Comment:
Comments are closed for this entry.
About

Rohan Ranade's musings on anything and everything.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today