Charles Burton

Ranch Hand
+ Follow
since Jan 31, 2011
Charles likes ...
Netbeans IDE Java Linux
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
9
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Charles Burton

Paul Clapham wrote:You don't update the backing store based on what happens in the cell editor. You should update it based on what happens in the setValueAt() method of the table model.



Thanks, that got me on the right track. I'll post some code once I figure it all out.
9 years ago
So, before I describe what I'm trying to do I'll give my standard disclaimer. I'm coding to java 1.4 and will not be upgrading for a while. All code posted is handjammed in from a system that is airgapped and may have typos and not be as complete as I would like to make it.

Now, on to what I'm trying to do. I'm trying to make a JTable where one row is backed by a org.w3c.dom.Node. I want to be able to parse that node's attributes/values into the cells for editing. The editing will be done by different component types including JComboBoxes, JTextFields, and JCheckBoxes. Editing changes will be made using these components and reflected in the Node's attributes/values. Let me show you what I have so far.




Sample XML Node

9 years ago
And I misspelled your name, so Thank you again Darryl .
9 years ago
I actually had to look that one up, it looks like that is exactly what I need. I actually preferred to disable the combobox but wasn't sure how to go about it. Thanks again Daryll .
9 years ago
Ok, I'll post some code in here. My normal disclaimer applies, Java 1.4, it's handjammed with no possibility of copy paste so there may be typos. A description of what I'm doing is populating fields of my GUI with an XML document. I want to be able to create/destroy nodes based on how the fields are filled out. What I'm looking to do is not allow the combo box to change until all the fields are filled out.

9 years ago
Does anyone know if there is a way to keep the selected index of a JComboBox from changing if certain criteria are not met when the selection changes?
9 years ago
I'm glad it worked for you, so to describe what was happening in a little more detail. Because you weren't using a layout manager all of your components were getting stacked on top of one another. Your code was actually working fine, but because the component that was displaying it was underneath another one you couldn't see it happening. I do recommend taking the time to learn GridBagLayout, it can be fairly complicated, but it really is good to know gives you much more control over how the gui looks. There is a bit of a learning curve, but once you get it, it's actually not too bad. I'v actually used it to dynamically generate filter buttons and whatnot in a nice neat grid.

http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html

Good luck!
9 years ago

I just copied what was in the book, Head First Java, 2nd Edition. I'm sure there's more efficient ways to make this stuff, but this is my first programming language I'm learning so it'll be awhile before I worry about that.



It's a good book, that's the one that I used to learn Java and they have a lot of really good examples in there. You just have to be careful because some of the examples are a little bit off sometimes.
9 years ago
On lines 35 -36 try adding them to the main panel with some kind of layout. I think your objects are getting stacked on top of eachother, sorry I can't test it for you the computer I'm using doesn't have a JDK. It should look something like this.

9 years ago
If you're very concerned about time you may want to consider another language too, while fast java isn't really considered realtime. However, if it's fast enough and you want to test the amount of time it does take try getting the time in millis just before you start to process the image and another just after. Store them somewhere so you can use them for later analysis and then print that analysis to the console. Probably will be much faster for you.
9 years ago
So here's the updated code taking into account all of Darryl's suggestions that I could.

9 years ago
You could try making a public method that sets running to false which will break that loop and let the thread exit cleanly. The thread stop() method is rarely a good idea, it's much better to let the thread finish processing. Inside the loop you could also add a conditional test for every iteration, that will allow you cleanly break all connections and close your streams so that you don't run into problems with hung resources.
Did you try this?

9 years ago
Oh, and I like your mention of using a set to back the ListModel with. I had thought of that, but because the ListItem value variable will always be different due to timestamps embedded in the string the objects will always be different. They're also embedded at the client side and applied whenever they're generated so I can't really move them to after the de-duplication portion either.
9 years ago
You're definitely correct about the unnecessary casting to ListItem, I actually only had a short little while to throw this together and run an overnight profile on it. I'm not sure if you're familiar with the Dice algorithm, but when I'm doing the de-duplication of the items contained in the list it's a percentage based differece. The way it works is I take the tracker line from each ListItem with the same number of lines and the same originating source and first compare them to see if they're equal, failing that it runs through the dice. I tried to make sure that the algorithm is run as little as possible. Anyway the way it flows is that once it fails all the original tests meaning it has the same originating source, the same number of lines, and is not equal I dice it. What happens when it gets diced is each string is broken down into a set of bigrams, I compare the two sets of bigrams and then calculate a difference in the tracker based on a percentage. The math for the computation is double finalNum = (2 * totalbigrams)/(nx.size() + ny.size();. I also don't abort adding a new item, it just removes all the previous examples that are within that threshold allowance. If you look at lines 32 and 33 you'll see that after I have removed all previous examples of this message I unconditionally add it. There is no need to maintain previously added ListItems because this is merely notification, the messages are added to the database already and kept no matter if they are cleared in the message window. I didn't post the methods here, but there's actually buttons to adjust the threshold of the dice algorithm up and down.

You have a filteredList.add(li); that is unconditionally executed when filter is not the empty String (line 37). That should probably be wrapped in the same condition you use in setFilter(...) -- if (filter.equals(li.getSource())


Excellent catch, thank you.

I would like to thank you as well, you've been very very helpful.
9 years ago