Java JEditorPane always enable text - java

How can I define Java JEditorPane to be able to always read text from the user, include after clicking on button, Now when i typing text and i click on some button on the screen, I need to click again on the JEditorPane so I could be able to typing more text.

Looks like the problem is lost focus. You can make the button not focusable
theClickButton.setFocusable(false);
Or return focus to the JEditorPane in the end of the button's action
editorPane.requestFocus();

Related

jPanel shows empty tooltip text

I have a few radio buttons and then a checkbox, I have tooltip's for the radio buttons but not the checkbox. Which works okay, unless I get a radio to display it's tool tip text and then quickly move to the checkbox, before the tip disappears, and now I have my mouse on the checkbox but it is displaying the tooltip for the previously moused over radio button.
I tried setting a blank ("") tool tip for the checkbox, which works okay except that it displayed a very small tooltip square.
Is there anyway to either force the previous tooltip to go away or to properly set a nothing tooltip for the checkbox?
radioButtonsetText("text");
radioButton.setToolTipText("tooltip text");
checkBox.setText("text");
checkBox.setToolTipText("");
or to properly set a nothing tooltip for the checkbox?
Components don't have a tooltip by default. So don't set the tooltip and your won't have a problem.
If you set the text and want to remove it the try using:
component.setToolTipText(null);

Which listener can know that the JTextPane value is changed?

I would like to know when JTextPane content is changed. I implemented a keyboard listener, but it is only detecting keyboard events. If the user pastes text via mouse or drag the text inside, then I am not enable to detect the JTextPane value is changed. Which event listener can tell me that the JTextPane value is changed?
you have to look for DocumentListener

I have two input text box and one button, I want to click on button than switch one text box contain to other text box

I have two input text box and one button, I want to click on button than switch one text box contain to other text box in jsf
write a javascript for transferring the content from one textbox to another textbox.
Trigger the script on the button "onclick" event.
Try a code on your own. If you have any troubles, i can help you..!!!

Jtextpane click to create popup menu effect on selection not as intended

I have a JTextPane sitting in a JFrame, with a popup menu that is assigned to the JTextPane through the JTextPane.setComponentPopupMenu method.
I want to give the JTextPane a "Word-like" popup behavior. By that I mean, if you right click outside of your current text selection, the caret will reposition to where you right clicked, with menu options that affect a text selection (such as cut, copy, or bold) disabled. If you right click within your current text selection, the popup will appear with options that effect text selection enabled, the text selection will persist, and the caret will not move.
The problem is I cannot seem to find where I can put the code that handles the selection change. I tried:
Using the "PopupMenuWillBecomeVisible" event which is triggered before a popup becomes visible. The event passed into this method does not contain any mouse event information so there is no way for me to use viewtomodel to find out how to modify the selection. I could use MouseInfo but that seems dubious at best.
Using MousePressed/MouseReleased events in the JTextPane or JFrame. Apparently, neither of these events are invoked when a popup menu is triggered. In fact, I still can't determine what the parent component of my popup menu is. (I did read that in windows "MouseReleased" is the popup trigger, while in other systems "MousePressed" is the trigger. I tried both and neither worked).
So, I guess the problem is that I can't seem to find a place to put code where it would be called before the popup menu becomes visible, but has awareness of the mouseEvent that triggered the popup menu. I must be missing something here.
with a popup menu that is assigned to the JTextPane through the JTextPane.setComponentPopupMenu method.
You can use the older approach of displaying the popup based on your own custom MouseListener.
See the section from the Swing tutorial on Bringing Up a Popup Menu. Now you have access to the MouseEvent so you can convert that point to a point in the Document so you know where the click was made, on selected or unselected text.

Keeping selection after clicking a JButton to style text

I'm making a fairly simple text editor, and I have a question about my style buttons. When I highlight text and click my "bold" button, the text bolds as expected, but my selection is not longer visible. I can still unbold the selection, italicize it, or underline it, but you just can't see what is selected. So, I'm wondering if there is a setting that will allow me to click the button, but keep my selection? I tried a JMenuItem instead of a JButton, and that seemed to work, but then it made my toolbar look quite bad. Sample code below.
//frame and pane creation up here
JToolBar tool = new JToolBar();
JToggleButton boldButton = new JToggleButton("Bold");
boldButton.addActionListener(new StyledEditorKit.BoldAction());
tool.add(boldButton);
Any help is appreciated.
So, I'm wondering if there is a setting that will allow me to click the button, but keep my selection?
boldButton.setFocusable( false );
As you noticed, the selection is still there but clicking on the toolbar button removes the focus from the text pane and hides the selection. You need to set the focus back using requestFocus. However, you will need to write your own action listener to add the focus code - you could extend BoldAction to do this.

Categories