Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I created a swing application which has a string named textField, and I need to append in a string named textArea. My Problem is; when it appends, it doesn't align, since the names are different .
I want to make it accept 25 characters only, and if less than 25 were entered they are filled with spaces.
Is there any way this can be done? I Have been on it since morning without making any headway.
Any suggestion would be greatly appreciated, thanks in advance.
Every Text Component in java associates with a model to maintain it's text content known as Document. A Document has: DocumentListener to listen to changes made to it which generates event on it's content update. you can also use DocumentFilter with Document to change how the text component's data is set. You can implement certain customizations either by installing a document filter or by replacing a text component's document with one of your own.
Check out the example and tutorial:
How to write DocumentListener
Implementing a Document Filter
DocumentSizeFilter
Related
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 6 years ago.
Improve this question
I'm having some trouble with my code. I have a number of lists, lists 1, 2 and 3 contain elemets so that when I click them they appear in list 4.
My goal is to have a number appear in a JTextField that will change every time an element is added to list 4.
This is the code I have in order for me to do that but it doesn't work and I don't know why.
jtextfield.setText(java.lang.String.valueOf(list4.getModel().getSize()));
The java.lang.String is weird I know but eclipse told me to change it.
Thank you!
You should use a ListDataListener. An event will be generated any time the DefaultListModel is updated by adding or removing an item.
Then you simply invoke the code you posted above.
Read the section from the Swing tutorial on How to Write a ListDataListener for more information and working examples.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a problem with my project. I'm making a tool for numerical methods (a lesson in college). I have done nearly all of the project but I have a problem with my design.
When I resize it before making anything it resizes well but, if I set the size of the matrix after the matrice processes the panel isn't resizing.
The code works well if the rank is <=5, but the bigger matrices cause that problem.
I'm using window builder and the code is messy but I'll be glad if you try to help me.
Thanks for your helps!
Some of things that I noticed in your code.
Don't use null layout at all and avoid setBounds() method
Always hand over it to Layout manager to set the position and size the components.
Use ActionListener for JButton instead of MouseListener if you want to capture click event only.
Note: I can't run your code on my system due to character encoding issue. You have used some character other than English in your code.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I have a xml reader which reads the title and the name of a person in java from a rss feed. I accomplish this by using document builder in java. When I read the element title and element name, I put them into a concurrent hashmap. This is fine, I can get the values from the map. However I want this information to be stored there for some time limit and not call the document builder until this time limit has passed. But the problem is when I do not call the document builder and refresh the webpage my hashmap values seem not to be stored. Code is in java and wicket.
Thoughts ?
It may be that every time you're refreshing the page a new hashmap is built and the old one is simply discarded. You should make sure your data stays persistent.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to write a message in red colour on the log file in java using logger.debug method,is there any way to do it?
Logs don't support styled text! The software used to display them might use some cleverness to color different parts differently, but that is done purely in the software.
Logging itself is just plain text with no means of displaying a message in a particular colour (think of it as a txt file). So if you really want colour in your logs you need to encode that as formatting information which can later be interpreted by a text reader, log viewer or web browser.
Probably the easiest would be to use HTML for this. This could for example look like this:
<span class="error">02.01.13 14:23 Something bad happend</span>
<span class="info">02.01.13 14:24 This is just an info message</span>
and additionally providing a CSS file containing the styling information.
.info{ color: #000000; }
.error{ color: #FF0000; font-weight:bold;}
You could look for a plugin to your IDE if you want colorized logs.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to do the best lookup textfield for JAVA Swing like below:
This is actually not very easy to achieve, not if you want a flexible and re-usable solution at the end of the process.
You need a JTextField (well, okay, that was obvious), a JList and a JPopupMenu or JWindow.
You need some kind of filtering mechanism that can take a String and produce a List of matches, which can then be displayed within the JList. This will require you to provide a ListCellRenderer for you particular implementation.
You will need to attach a DocumentListener to the JTextField. When the document is updated/changed, you will need to pass the text of the text field to your filtering engine to find all the possible matches and display them within the JList.
If the popup is not visible, you will need to make it visible, taking into account that the list might not fit on the screen based on where the text field is. If it is visible, you may need to re-pack the window to better accomidate the available options (if any)
If the user leaves the field, you will need to decide if you want to auto complete the text based on the first match, invalid the field or leave the text as is and close the popup if it's visible.
If the user clicks on a value, you will need to extract the String representation of the item and apply it to the text field and close the popup.
You will need to add key bindings to the text field to accommodate the down arrow which could open the popup window and/or move to the first item in the list. This will trigger a lose of focus, so you need to be prepared for it.
You will probably also want to provide a Escape keyboard binding for the popup/field so the user can dismiss the popup