• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple TextEditor, question?

 
Igor Stojanovic
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am writing simple Text editor just to get familiar with basic swing components and to learn whats going on "under hood" when I use Eclipse Visual Editor...

Here is my problem: "Components are enabled initially by default. A component may be enabled or disabled by calling its setEnabled method. " I have several JMenuItems (Cut,Copy,Delete,Paste) in my JMenu "Edit" and they are enabled by default, but I want them to be disabled if user didn't select some text and after he select some part of text I want to enable these components? How to accomplish this kind of components behavior?

P.S. In my constructor I disable Cut,Copy,Paste and Delete because user should not be able to use them if there is no selected text but later when he selects something these components should be enabled for him,which kind of event I have to send after user selects part of text?

kind regards
Igor
 
Pat Hays
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Igor

You can use addCaretListener. It should work.
---------------------------------------------------------
jTextPane1.addCaretListener(new CaretListener() {
public void caretUpdate(CaretEvent e)
{
jTextPane1_caretUpdate(e);
}

});
...
...
...
private void jTextPane1_caretUpdate(CaretEvent e)
{
System.out.println("\njTextPane1_caretUpdate(CaretEvent e) called.");
System.out.println(">>" + "location:" + e.getDot() + ";\tthe location of other end of the logical selection:" + e.getMark());
// TODO: Add any handling code here

}
 
Igor Stojanovic
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Pat,

I implemented your code and it works!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!