Posts

📁 Java File Handling

  📘 1. Introduction to File Handling in Java File handling in Java allows programmers to store, retrieve, and manipulate data in files stored on the disk. This is achieved using classes from the java.io and java.nio packages. 📁 2. File Class Overview Java provides a File class in the java.io package to represent the pathnames of files and directories. 📘 1. Creating a File import java.io.File; import java.io.IOException; public class CreateFile { public static void main(String[] args) { try { File file = new File("example.txt"); if (file.createNewFile()) { System.out.println("File created: " + file.getName()); } else { System.out.println("File already exists."); } } catch (IOException e) { System.out.println("An error occurred."); e.printStackTrace(); } } } ✍️ 2. Writing to a File import java....

Font Color Change

  //===========================Step1===    int color_start,color_end;     private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                                  // TODO add your handling code here:                          color_start = textPane1.getSelectionStart();              color_end = textPane1.getSelectionEnd();         FontColorDailog.setVisible(true);     }                                         //==========OnChange Listiner  initComponant()     jColorChooser3.getSelectionModel().addChangeListener(e -> {      StyledDocument doc = tex...

Save as RTF And Read RTF

  ==================Save==============     private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                                  // TODO add your handling code here:       JFileChooser fileChooser = new JFileChooser();         fileChooser.setDialogTitle("Save As");         int userSelection = fileChooser.showSaveDialog(null);         if (userSelection == JFileChooser.APPROVE_OPTION) {             File fileToSave = fileChooser.getSelectedFile();             String filePath = fileToSave.getAbsolutePath();              try (FileOutputStream fos = new FileOutputStream(fileToSave)) {                 new RTFEditorKi...

Open And Read File

  JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Open File"); int userSelection = fileChooser.showOpenDialog(null); if (userSelection == JFileChooser.APPROVE_OPTION) {     File selectedFile = fileChooser.getSelectedFile();     StringBuilder contentBuilder = new StringBuilder();     try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {         String line;         while ((line = reader.readLine()) != null) {             contentBuilder.append(line).append("\n");         }         textPane1.setText(contentBuilder.toString()); // Show content in textPane1         System.out.println("File loaded: " + selectedFile.getAbsolutePath());     } catch (IOException ex) {         Logger.getLogger(DashBoard.class.getName()).log(Level.SEVERE, null, ex); ...

Save File Dialog

     JFileChooser fileChooser = new JFileChooser();         fileChooser.setDialogTitle("Save As");         int userSelection = fileChooser.showSaveDialog(null);         if (userSelection == JFileChooser.APPROVE_OPTION) {             File fileToSave = fileChooser.getSelectedFile();             String filePath = fileToSave.getAbsolutePath();             // Add .sabir extension if it's not present             if (!filePath.toLowerCase().endsWith(".sabir")) {                 filePath += ".sabir";                 fileToSave = new File(filePath);             }             System.out.println("Save file to: " + fileToSave.getAbsolutePath());       ...

Short Code Class

 //========================= /*  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license  * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template  */ package mdi; import javax.swing.JTextPane; import javax.swing.JToggleButton; import javax.swing.SwingUtilities; import javax.swing.text.AttributeSet; import javax.swing.text.Element; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; public class StylesCollection { public void Font(JTextPane textPane, String styleName, JToggleButton toggleButton) {     StyledDocument doc = textPane.getStyledDocument();     int start = textPane.getSelectionStart();     int end = textPane.getSelectionEnd();     if (start == end) return; // No text selected     // Get the first character's style in the selected text     Element element = doc.ge...

New OnchageColor And SectionMaintain

 //====================OnChage Event =============          jColorChooser1.getSelectionModel().addChangeListener(e -> {     Color selectedColor = jColorChooser1.getColor();     // You can now use the selectedColor or update a preview, etc.     //System.out.println("Selected color: " + selectedColor);     jLabel1.setForeground(selectedColor); }); //========================Set Style============================                    StyledDocument doc = textPane.getStyledDocument();                 int start = textPane.getSelectionStart();                 int end = textPane.getSelectionEnd();                                                   Style style = textPane.a...