This color is applied to the selected text. The set color button when pressed opens a JColorChooser dialog where a color can be selected. Note that the bold, italic and underline buttons act to toggle their respective attribute on the selected text. This brings the cursor back to the editor where it was previously before the cut button was pressed. The listener's actionPerformed() method has a single statement: editor_.requestFocusInWindow(). After some text is selected in the editor and a button (for example, the cut button) is pressed, the cursor does not return to the editor. The EditButtonActionListener is an ActionListener attached to all the six buttons.
Eclipse selected text color code#
The following code snippet shows how the cut action button is defined: JButton cutButton = new JButton(new CutAction()) ĬutButton.addActionListener(editButtonActionListener) The bold, italic and underline format actions are defined in the StyledEditorKit. These actions are defined in the DefaultEditorKit. The cut, copy and paste edit functions are created from Actions supplied to the JButtons. Cut, copy, paste, bold, italic and underline
In the finished application type in some text edit text using cut (CTRL-X), copy (CTRL-C) and paste (CTRL-V).ģ.1. JScrollPane editorScrollPane = new JScrollPane(editor_) Įditor_.setDocument(new DefaultStyledDocument()) įrame_.add(editorScrollPane, BorderLayout.CENTER) The following code snippet shows the statements used to build the GUI: frame_ = new JFrame(MAIN_TITLE) The JTextPane is associated with a DefaultStyledDocument this is for editing the styled text (like bold, italic, various fonts and sizes, colors, etc.). The GUI look and feel is set as Nimbus and the default font for the text editor is set as SansSerif with 18 point size.
Eclipse selected text color download#
The Java source code for the finished application can be downloaded from the Download section below.