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.addStyle("BoldStyle", null);

                StyleConstants.setBold(style, true);

                

                doc.setCharacterAttributes(start, end - start, style, false);

 

///==============Maintain Selection Text=============               

SwingUtilities.invokeLater(() -> {

    textPane.setSelectionStart(start);

    textPane.setSelectionEnd(end);

    textPane.requestFocusInWindow();      // 🔹 Ensures textPane has focus

    textPane.getCaret().setSelectionVisible(true); // 🔹 Forces selection highlight to show

});

      


Comments

Popular posts from this blog

Remove (Clear) and remove Selected element

JSpinner

🛢️ MySQL Connection & CRUD Operations in Java