Building a Java text editor
JFileChooser
(file open dialog) for text files. If the user selects a file and clicks the OK button, then the event handler opens that text file and puts the text into the JTextArea
.
JFileChooser
component from the Swing Containers page of the palette.
UI
folder in the component tree to drop the component. (If you click in the UI designer, the component will be dropped into the wrong section of the tree.)
jMenuItem2
).
actionPerformed()
event and insert the following code:
//Handle the File|Open menu item. // Use the OPEN version of the dialog, test return for Approve/Cancel if (JFileChooser.APPROVE_OPTION == jFileChooser1.showOpenDialog(this)) { // Display the name of the opened directory+file in the statusBar. statusBar.setText("Opened "+jFileChooser1.getSelectedFile().getPath()); // Code will need to go here to actually load text // from file into TextArea. }
JBuilder Foundation users skip this step and go to Step 9.
JFileChooser
and JColorChooser
, will appear in the language the application is running in. Add the following line of code to the TextEditFrame
class in TextEditFrame.java
:
IntlSwingSupport intlSwingSupport1 = new IntlSwingSupport();Your code now looks like this:
public class TextEditFrame extends JFrame { IntlSwingSupport intlSwingSupport1 = new IntlSwingSupport(); JPanel contentPane; JMenuBar menuBar1 = new JMenuBar(); JMenu menuFile = new JMenu(); ... }
import com.borland.dbswing.*;
and the dbSwing library. In this tutorial, this was taken care of automatically when you added the dbSwing FontChooser
component.
Now, when you run your application in other languages, the JFileChooser
and JColorChooser
will appear in the appropriate language.
"Adding and configuring libraries" in "Creating and managing projects"