Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have set up my application so that when I press Ctrl+Z, my UndoManager will undo the last entry. However, for some reason, Ctrl+H will also do this, and I have no idea why.
Here is my source code.
when I press Ctrl+Z, my UndoManager will undo the last entry. However, for some reason, Ctrl+H will also do this,
Ctrl+H is not invoking your UndoManager.
Ctrl+H, is a Key Binding to delete the previous character in a text component.
This is easy to test. Just type some text into the text component. Then set the caret to a different position in the text component. The character deleted will be the character at the current caret position, not the last character typed into the text component.
You can check out Key Bindings for a program that displays all the default Key Bindings for a given component.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The title says it all, is there any real reason that:
print("\t");
Can't do what
print(" ");
does?
Clarification: I am not asking if one is better than the other, I am asking if one can do anything that the other can not.
The tab character is not the same as inserting spaces and when you hit tab on your keyboard, your IDE appears to have entered multiple spaces for you.
Example:
System.out.println("A\tB");
System.out.println("123\t456");
Outputs:
A B
123 456
The tab character has moved the cursor to the next tab stop, which has helped align these columns.
Yes, it is the same. \t is the escape sequence for the tab space.
System.out.println("Hello\tWorld");
It will provide:
Hello World
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
If I have a grid of 9 panels within another panel and I want to be able to click a subpanel and on click, send the content of that panel to a 'selected panel' area, how would I go about this? (Imagine a character select page for a videogame. When a player selects their character, it shows an expanded view of the character in a 'selected' pane)
I'm thinking of mouseListeners for each subpanel and retrieving the clicked component but I don't understand how I can copy that clicked component to a 'selected' area.
Add your items to a JList or single-colum JTable. Add a ListSelectionListener to your chosen component. Specify ListSelectionModel.SINGLE_SELECTION. In your valueChanged() handler, the ListSelectionEvent will tell you what value was selected. Use that information to fill in the fields of an adjacent panel. A complete example, illustrated below, is seen here.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a project where some random text is displayed in a JScrollPane. This text is coded in and is not editable. Is there a way to create a mouse click event on each line of text and have that event take the text clicked on and have it display in a textField?
The part that stumps me is how to act on a line of text versus a clickevent on a button per se. Below is a rendering of the project and the areas containing the text.
Presumably your text is displayed in a JTextArea or JTextPane, so you would add a MouseListener to the component. Then when the MouseEvent is generated you can get the caret position. Using the caret position you can then use the Utilities class. It has methods like:
getRowStart(...)
getRowEnd(...)
Using these values you can then get the text from the Document using the getText(...) method.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
im stuck on a simple question, i want to display formatted text in a swing control and keep on adding new values into it, i don't want to use .setText(.getText + text) for personal reasons, (something like the append method for text area is what I am looking for) I've tried JEditorpane, Textpane but all of them do not have append method. Which swing control should I use?
While JEditorPane has no append method, you can certainly add text to its Document via its insertString(...) method, and I suggest that you look into doing this.
Edit
You ask:
it worked it out but it seems it works like setText, all the previous data vanishes.. how do i keep the previous data ?
Are you correctly passing in the first parameter, the offset? This should be the length of the current Document.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Requirement is like:
I want to take input values from user in frame but no of inputs is also decided by user.
So first,
In frame,I want user to write no of values in one text field
so as soon as user writes that many text fields should be generated in the same frame.
How can this be done?
Is this possible or is there any good way available for this?
I would use a table instead. Either the user can directly edit the table or you provide a "Add New Row" button. In my opinion changing the UI layout (adding text fields) at runtime is bad design.