Results 1 to 7 of 7
  1. #1
    Java.child is offline Member
    Join Date
    Sep 2008
    Posts
    32
    Rep Power
    0

    Default basic text editor in Swing

    Hello Experts,

    I am trying to put the basic text editor feature in my application like <b>,<I>,<Font>.

    But I don't know how to do it.I am using Swing.

    I created Bold and Italic button but didn't write the button click code.Please help me if some body knows about that.


    Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    If it were me and I needed this, I'd look to see if someone has done this before. Perhaps Apache Commons has something that would help?

  3. #3
    Java.child is offline Member
    Join Date
    Sep 2008
    Posts
    32
    Rep Power
    0

    Default

    I tried on internet but not able to fine out.

  4. #4
    Java.child is offline Member
    Join Date
    Sep 2008
    Posts
    32
    Rep Power
    0

    Default

    Please help me as I tried to search on internet but not able to get anything.
    I want that when I click on <B> button,Text will change into Bold.

  5. #5
    Gudradain is offline Member
    Join Date
    Nov 2008
    Posts
    44
    Rep Power
    0

    Default

    Here is the solution.

    Java Code:
    public static void setStyle(JTextPane theTextPane, Style theStyle){
            int selectionStart = theTextPane.getSelectionStart();
            int selectionEnd = theTextPane.getSelectionEnd();
            
            StyledDocument theStyledDocument = theTextPane.getStyledDocument();
            
            theStyledDocument.setCharacterAttributes(selectionStart, selectionEnd-selectionStart, theStyle, true);
        }
    The code your button execute should be something similar. I just test it and it work.
    Unfortunately I'm not good with action and event so you need to figure the rest by yourself

  6. #6
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default

    are you trying to create simple text editor with GUI ?

  7. #7
    Gudradain is offline Member
    Join Date
    Nov 2008
    Posts
    44
    Rep Power
    0

    Default

    Quote Originally Posted by itaipee View Post
    are you trying to create simple text editor with GUI ?
    Hmmm. I'm trying it too. Why you ask?

Similar Threads

  1. Drag out text editor pane
    By p4ndaman in forum Eclipse
    Replies: 3
    Last Post: 07-21-2008, 04:19 PM
  2. SWT Text Editor Demo
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 04:35 PM
  3. SWT Text Editor
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-07-2008, 04:43 PM
  4. Problem in Text Editor
    By mustahsan4u in forum New To Java
    Replies: 2
    Last Post: 03-26-2008, 02:34 PM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 07:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •