First, you have to add a FontChooser dialog to your TextEditFrame class before it can be used by the menu item.
To set the frame and title properties,
Font
.
As a result, the following lines are added to the source code in the jbInit() method:
fontChooser1.setFrame(this); fontChooser1.setTitle("Font");Placing the FontChooser into the Component Tree and setting these properties creates code in your class that instantiates a FontChooser for your class, sets its title to "Font", and sets its frame to this. But this code won't show the dialog (make it visible), or make use of it in any way. That has to be done in the "event handler" for the Edit|Font menu item. Let's create that code now.
For menus, buttons, and many other Java UI components, actionPerformed is the main user event of interest, the one you should hook for responding to the user operating that menu or button. Notice that a menuItem has only one event, an actionPerformed event.
When you double-click the value field for an event in the Inspector, the name of the event handling method appears. If the method doesn't already exist, this will show the proposed default name for a new event handling method. For this new event handler in this tutorial, the value will probably be menuItem5_actionPerformed. The default value is just fine in this case.
fontChooser1.show();
So your method should now look like this:
void menuItem5_actionPerformed(ActionEvent e) { fontChooser1.show(); }
Try the Edit|Font menu item and see what happens. You should be able to get a Font Chooser dialog to appear. If not, check that you set its frame property to this. With what you've made so far, the FontChooser dialog should show.
Try typing some text into the text area of your application and then using the Edit|Font menu item. Notice that you don't see any font changes take effect yet. This is because you aren't using the results from the FontChooser to change the text in the text area. Let's do that next.