1

Hi guys
I am in a strange situation: there is a JToggleButton with a JTextPane as a child component. If I click on the JTextPane, the relative button's events don't go in action (because he understands that i want to click on the JTextPane, which i'd like to set "unclickable").

How could i solve this? :)

Oneiros
  • 4,328
  • 6
  • 40
  • 69
  • Do you want the action to be performed when clicking on the JTextPane or not? this is not so clear from your question... – MByD May 27 '11 at 19:07
  • sorry, my english is not very good :) yes, i want the togglebutton's action to be performed when i click on the textpane... the textpane must be just a view-component, like a simple label, without gaining any focus or clicks – Oneiros May 27 '11 at 19:13
  • Why won't you simply use `setText()` on the button? – MByD May 27 '11 at 19:17
  • because it's not so simple: this togglebutton is like a little container with 2 labels and 2 textpanes – Oneiros May 27 '11 at 19:20
  • You may be able to do it with addFocusListener... – MByD May 27 '11 at 19:27
  • 2
    I don't understand how a toggle button can contain 2 labels and text panes. Strange design. Post your SSCCE (http://sscce.org) that demonstrates the problem. Maybe we can suggest something different. – camickr May 27 '11 at 21:06

1 Answers1

1

You can just do something like this

aJToggleButton tButton=new aJToggleButton();//contains JTextPane
tButton.getTextPane().addActionListener(this);

public void actionPerformed(ActionEvent e)
{
  ((aJToggleButton )((JTextPane)e.getSource()).getParent()).setSelected(true);
}

Anyway, it would be more helpful to see the component docs... Still I guess, the snippet touches the conception

Good luck

user592704
  • 3,674
  • 11
  • 70
  • 107