Text editor with java

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

📝 PHNotepad is a simple Java text/code editor (notepad) written in Java. It has also nice features such as Search tool, Find/Replace text/code, Auto-completion, Nice Image Buttons for better UX, etc.

License

pH-7/Simple-Java-Text-Editor

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

PH NotePad is a simple and light text editor (notepad) written in Java.

  • Search tool (to search text/keywords easily in the code) + highlighting the code found.
  • Find/Replace text/code.
  • Auto completion for Java and C++ keywords (files need to be saved as .java/.cpp). It can be easily expanded to support pretty much any number of languages.
  • Drag and Drop (drag files into the text area and they get loaded).
  • Nice image buttons for better UX.

Example Java Text Editor

  • Pierre-Henry Soria: hi [AT] ph7 [D0T] me
  • Achintha Gunasekara: contact [AT] achinthagunasekara [D0T] com

Download the Jar file and double click to run

Or run java -jar SimpleJavaTextEditor.jar from the command line

You can also generate easily a new jar file with the following command when you are in src/ directory jar cmvf ../manifest.mf ../SimpleJavaTextEditor.jar simplejavatexteditor/*.class

Icons directory and its files must be present on the path when running the application (so you will have to move «icons/» into «src/» directory)

Читайте также:  Совместить два изображения python

Apache License, Version 2.0 or later; See the license.txt file in the notepad folder.

About

📝 PHNotepad is a simple Java text/code editor (notepad) written in Java. It has also nice features such as Search tool, Find/Replace text/code, Auto-completion, Nice Image Buttons for better UX, etc.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A text editor in java with support for multiple document interface (MDI)

sdht0/simple-text-editor

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This is a simple text editor with multiple document interface (MDI), built in Java using the Swing classes. A tabbed pane has been implemented for working with many files at once.

The project has been written, and built using Eclipse IDE for Java Developers (version: Indigo) on Ubuntu 11.10 (64-bit) OS.

  • Create new file, open files from disk, save files
  • Cut copy paste operations
  • find and replace text
  • displays line numbers
  • wrap text enable or disable
  • select different font and font size as display settings for text

Thus, all basic features of a text editor have been implemented.

  • SEditor.java: the Main file of the program, creates the document main window.
  • AboutDialog.java: creates an about dialog with brief information about the project.
  • CustomTabButton.java:creates the tabs with a cross button for closing tabs.
  • FindReplaceDialog.java: creates the find/replace dialog and handles these operations.
  • FontChooser.java: creates font chooser dialog with options to set font, font size and attributes: bold and italics.
  • MenuDetail.java: A structure class for handling details for each menu item.
  • TextArea.java: Creates a text area for each tab, includes file details, line number bar, caret posiiton bar, and undo redo operations support.
Читайте также:  File created time in java

-> docs: the javaDoc of the project

-> eEditor.jar: the executable project file

The text editor can be run from the command-line by executing: java -jar sEditor.jar , provided java is present in the system path. Else full path to java executable has to be given

Источник

Build a text editor using Java swing

Hi, we are learning how to build a text editor using Java or we can say a simple notepad. Java swing components are lightweight as compared to other GUI components of Java. It is also platform-independent.

So let’s discuss how to build this project using Java swing. First, let’s discuss the components required to build this project are Text area require to writing or reading the text, then we require some menu items like file, edit, and info file contains options like open, save, new and exit whereas edit contains cut, copy, paste, undo and redo and finally on info contains information about developer and text editor. Now we require a scroll bar that scrolls the page according to the requirement of the user. Now we need to add functionality to each menu item to cut, copy, and past we require only one line of code as given below respectively.

textArea.cut(); textArea.copy(); textArea.paste();

Where textArea is the object of the JTextArea which is used for the Text Area component. Now we require to add undo and redo functionality so we require to create an object of UndoManager class and then attach this object with textArea.

UndoManager undo = new UndoManager(); textArea.getDocument().addUndoableEditListener(undo);

Now use this object and add undo and redo functionality to the menu items by writing a single line of code for each one.

Next, we require to add functionality to new, open, save and exit menu items. Let’s being with new for it we just need to clear the text in the teaxtArea component so for that, we need to set the empty string in it.

Now it time to save and open both of them the code require to add functionality in them is similar. First, we will code for the functionality to save a file.

JFileChooser filechooser = new JFileChooser("f:"); int temp = filechooser.showSaveDialog(null); if (temp == JFileChooser.APPROVE_OPTION) < File file = new File(filechooser.getSelectedFile().getAbsolutePath()); try < FileWriter filewriter = new FileWriter(file, false); BufferedWriter bufferwr = new BufferedWriter(filewriter); bufferwr.write(textRegion.getText()); bufferwr.flush(); bufferwr.close(); >catch (Exception ex) < JOptionPane.showMessageDialog(frmTextEditor, ex.getMessage()); >>

Now we will code for opening a file in the text editor.

JFileChooser filechooser = new JFileChooser("f:"); int temp = filechooser.showOpenDialog(null); if (temp == JFileChooser.APPROVE_OPTION) < File file = new File(filechooser.getSelectedFile().getAbsolutePath()); try < String str="",str1=""; FileReader fileread = new FileReader(file); BufferedReader bufferrd = new BufferedReader(fileread); str1=bufferrd.readLine(); while((str=bufferrd.readLine())!=null) < str1=str1+"\n"+str; >textRegion.setText(str1); > catch(Exception ex) < JOptionPane.showMessageDialog(frmTextEditor, ex.getMessage()); >>

Now finally we will code for exiting from the text editor through the exit menu item.

frmTextEditor.dispatchEvent(new WindowEvent(frmTextEditor, WindowEvent.WINDOW_CLOSING));

finally, we discuss the major and some minor parts of the code of the project so to completely deploy or build this project we require complete code which is attached below just copy it and build your own text editor.

import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JMenuBar; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JRadioButtonMenuItem; import javax.swing.JLabel; import javax.swing.JSeparator; import javax.swing.JEditorPane; import javax.swing.JFileChooser; import java.awt.CardLayout; import javax.swing.JTextArea; import javax.swing.SpringLayout; import javax.swing.undo.UndoManager; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.awt.event.ActionEvent; import javax.swing.BoxLayout; import java.awt.BorderLayout; import javax.swing.JScrollBar; import javax.swing.JScrollPane; public class text_editor < private JFrame frmTextEditor; /** * Launch the application. */ public static void main(String[] args) < EventQueue.invokeLater(new Runnable() < public void run() < try < text_editor window = new text_editor(); window.frmTextEditor.setVisible(true); >catch (Exception e) < e.printStackTrace(); >> >); > /** * Create the application. */ public text_editor() < initialize(); >/** * Initialize the contents of the frame. */ private void initialize() < frmTextEditor = new JFrame(); frmTextEditor.setTitle("Text Editor"); frmTextEditor.setBounds(100, 100, 505, 490); frmTextEditor.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frmTextEditor.getContentPane().setLayout(new BorderLayout(0, 0)); JTextArea textRegion = new JTextArea(); frmTextEditor.getContentPane().add(textRegion, BorderLayout.CENTER); JMenuBar menuBar = new JMenuBar(); frmTextEditor.setJMenuBar(menuBar); UndoManager undo = new UndoManager(); textRegion.getDocument().addUndoableEditListener(undo); JMenu mnFile = new JMenu("File"); menuBar.add(mnFile); JMenuItem mntmNew = new JMenuItem("New"); mntmNew.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent arg0) < textRegion.setText(""); >>); mnFile.add(mntmNew); JMenuItem mntmSave = new JMenuItem("Save"); mntmSave.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent e) < JFileChooser filechooser = new JFileChooser("f:"); int temp = filechooser.showSaveDialog(null); if (temp == JFileChooser.APPROVE_OPTION) < File file = new File(filechooser.getSelectedFile().getAbsolutePath()); try < FileWriter filewriter = new FileWriter(file, false); BufferedWriter bufferwr = new BufferedWriter(filewriter); bufferwr.write(textRegion.getText()); bufferwr.flush(); bufferwr.close(); >catch (Exception ex) < JOptionPane.showMessageDialog(frmTextEditor, ex.getMessage()); >> > >); mnFile.add(mntmSave); JMenuItem mntmOpen = new JMenuItem("Open"); mntmOpen.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent e) < JFileChooser filechooser = new JFileChooser("f:"); int temp = filechooser.showOpenDialog(null); if (temp == JFileChooser.APPROVE_OPTION) < File file = new File(filechooser.getSelectedFile().getAbsolutePath()); try < String str="",str1=""; FileReader fileread = new FileReader(file); BufferedReader bufferrd = new BufferedReader(fileread); str1=bufferrd.readLine(); while((str=bufferrd.readLine())!=null) < str1=str1+"\n"+str; >textRegion.setText(str1); > catch(Exception ex) < JOptionPane.showMessageDialog(frmTextEditor, ex.getMessage()); >> > >); mnFile.add(mntmOpen); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent e) < frmTextEditor.dispatchEvent(new WindowEvent(frmTextEditor, WindowEvent.WINDOW_CLOSING)); >>); mnFile.add(mntmExit); JMenu mnEdit = new JMenu("Edit"); menuBar.add(mnEdit); JMenuItem mntmCut = new JMenuItem("Cut"); mntmCut.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent e) < textRegion.cut(); >>); mnEdit.add(mntmCut); JMenuItem mntmCopy = new JMenuItem("Copy"); mntmCopy.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent e) < textRegion.copy(); >>); mnEdit.add(mntmCopy); JMenuItem mntmExi = new JMenuItem("Paste"); mntmExi.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent e) < textRegion.paste(); >>); mnEdit.add(mntmExi); JMenuItem mntmUndo = new JMenuItem("Undo"); mntmUndo.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent e) < undo.undo(); >>); mnEdit.add(mntmUndo); JMenuItem mntmRedo = new JMenuItem("Redo"); mntmRedo.addActionListener(new ActionListener() < public void actionPerformed(ActionEvent e) < undo.redo(); >>); mnEdit.add(mntmRedo); JMenu mnInfo = new JMenu("Info"); menuBar.add(mnInfo); JLabel lblThisEditorIs = new JLabel("This Editor is designed in Java Swing"); mnInfo.add(lblThisEditorIs); JSeparator separator = new JSeparator(); mnInfo.add(separator); JLabel lblDevelopedByYashika = new JLabel("& Developed By Yashika Jain"); mnInfo.add(lblDevelopedByYashika); JScrollPane scrollabletextRegion = new JScrollPane(textRegion); scrollabletextRegion.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollabletextRegion.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); frmTextEditor.getContentPane().add(scrollabletextRegion); > >

Thank you for reading this Blog.

Читайте также:  bla

Источник

Оцените статью