void menuItem6_actionPerformed(ActionEvent e) { }
// Handle the "Foreground Color" menu item // Pick up the existing text (foreground) color from the TextArea // and put it into the ColorChooser before showing // the ColorChooser, so that we are editing the // existing text color. colorChooser1.setValue(textArea1.getForeground()); // Before showing it, set the title of the dialog for its // particular use in this event (for setting the text color) colorChooser1.setTitle("Set Text Color"); // Show the ColorChooser. // Since the ColorChooser is modal by default, // the program will not return from the call // to show until the user dismisses the ColorChooser // using OK or Cancel. colorChooser1.show(); // Now that the user has dismissed the ColorChooser, // obtain the new color from the ColorChooser's // value property. First test the result property to see if the // user pressed OK. if (colorChooser1.getResult() == ColorChooser.OK) { // set the foreground of textArea1 to the color // value that can be obtained from the // value property of colorChooser1. This // color value is what the user set // before pressing the OK button textArea1.setForeground(colorChooser1.getValue()); }
colorChooser1.setValue(textArea1.getBackground()); colorChooser1.setTitle("Set Background Color"); colorChooser1.show(); if (colorChooser1.getResult() == ColorChooser.OK) { textArea1.setBackground(colorChooser1.getValue()); }
If you don't see a dialog appear when expected, double-check that you've set its frame property to this. You can also choose View|Execution log to check to see if exceptions have been thrown.