Al Swensen

Greenhorn
+ Follow
since May 02, 2006
Al likes ...
jQuery Firefox Browser PHP
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Al Swensen

Sorry... I posted there first, because I couldn't get to the Java Ranch site when I had this problem. Is there something wrong with getting mutiple opinions on a problem? Java Ranch is always my first choice for getting help with programming problems, as I've been helped several times here -- I just coudn't get to the site the other day. So sorry if I "wasted your time", that wasn't my intention at all. :/
17 years ago
Hi, I'm having some trouble trying to get my JComboBox working properly... Basically, I have a JMenuBar with several options, and depending on what the user chooses from that menu, a combo box will be populated with a different string of options. So for example, I have 2 JMenu items: "Cars" and "Animals." Clicking on the "Cars" option will populate a JComboBox with 3 options: "Chevy", "Ford", "Hyundai". Clicking on "Animals" will populate it with "Cat", "Dog", "Bird", "Fish".

How would that be done? I was looking for an example of using the ABstractListModel ant DefaultcomboBoxModel to do this but I couldn't find a whole lot on Google or on the Sun website and I'm not sure where to start. Any help would be great!
17 years ago
Yep, that did it.. thanks! It was a silly mistake on my part, I should've known better than to compare Strings with "==".
17 years ago

Originally posted by Ulf Dittmer:
So the parameter passing works whether the applet is jar'ed or not; that sounds as if the problem lies elsewhere. A few things to look into: is populateTable still being called? Does "data" have the correct value? Does "skill" have the correct value, whereever that is initialized? Are you certain that one of the 2 if-conditions is always true?



Oops, I mistyped part of that... the "skill" should be "data" (that's what happens when you're talking and typing at the same time! ), and there are a number of other conditions, I just posted the first ones. But yes, data should have the correct value, I'm passing my parameters in the html file like this:

So yes, it should definitely be true at some point. IT's very off, because it works perfectly before I JAR it, but it doesn't populate the table after I JAR it and run it.

Like I said, I also have a JMenu that uses the same method call that passes a value onto populateTable depending on what option is selected... that works fine. I just don't understand why it's not populating the table, it's like it's not calling the method or something when the files are JARed up.
17 years ago
I'm having some trouble trying to pass parameters from an HTML file to my applet. Basically, I'm passing one parameter to the applet at the moment called "name." Depending on what that value is, different data populates a JTable. This is how I'm getting the parameter from the HTML file:

Now, everything works perfect before I JAR everything... the applets gets the parameter and populates the JTable using a method call like:

But as soon as I place everything into a JAR file, the table doesn't get populated. the parameter seems to be passed, because I had a popup window with the parameter that was passed pop up to let me know it worked. Just... the JTable doesn't seem to be populating. Of course, I also have a JMenu with several options, which when clicked on will populate the table with the appropriate data... it looks sorta like this:


All this code does is copy the values of the column name array and table data array to the one used by my table model. I can't seem to get this to work when it's been JARed though... does anyone have any ideas?
[ May 30, 2006: Message edited by: Al Swensen ]
17 years ago
Hi, I've been working on a Swing program that works fine unless I try running it as an applet in a browser. Every time I run it, I get this error: "java.lang.NoClassDefFoundError: TestCalc$MyTableModel" and it doesn't start. The MyTableModel class is an inner class in the TestCalc class, and I can't figure out why it's saying that the class isn't found. If I run it as an applet in Eclipse, it works perfectly fine. but obiously, I'd like to run it in a browser! How can I fix this?
17 years ago
Bah, one more question. It's kinda related to my last one... Now I'm trying to take the value of the first cell in each row and compare it to a variable when the "calculate" button gets pressed. If the variable is smaller than the value in the cell, the cell should become red. I've set up a CustomTableCellRenderer which sorta works, but it sets the background before the variable can be set and I'm not sure how to make it so that it works how I'd like it to.

Here's the class that I have:

Thanks again for any help!
17 years ago
Thanks! I tried that and the program compiled, but when I run it I get a " java.lang.IllegalArgumentException: Cannot format given Object as a Number" exception... why would that happen?

EDIT: Figured that out. Stupid me, I put an extra "i++" in my for loop.

Thanks for your help!
[ May 18, 2006: Message edited by: Al Swensen ]
17 years ago
Sorry for the double post, but I didn't want to start a new topic about this. I just hit a roadblock while working on this... I want to be able to get a value from one cell in the table (which is a double in the array), and divide another variable (another double) by it. But apparently all values in the cells are Objects so I can't. How would I divide one variable by a cell's value?

Here's my test array:


and here's the loop that I'm currently trying to use which gets the value in the third cell over, divides a variable by it, and then sets the value of the fourth cell over:


Sorry if it's a stupid question, this whole JTable thing is kinda confusing!
17 years ago
Ok, I did that but I set up an ActionListener for a button to try it out, but the cell's value doesn't change unless you click the cell. I'd like it to change when the button is pressed. I'm using setValueAt and this is what the method looks like:


EDIT: Nevermind, I got it! I just had to add in "fireTableCellUpdated(row, col);" to the setValueAt method, and now it works great!
[ May 16, 2006: Message edited by: Al Swensen ]
17 years ago
True, but having a textfield hold data kinda makes it stand out (of course, if it's a different color than the rest of the table). Basically, I'm trying to redo an old project that I started with JavaScript by using Java instead. It's supposed to be a calculator-like application that does a calculation based on the "double" values in the array and outputs it into the textfield... I'll still be able to do that without a textfield, right?
17 years ago
Hi, I'm working on a project that displays data in a JTable (int, String, double, and a JTextfield). Everything is working fine, but I can't seem to get the JTextField to work correctly... it just shows up as "javax.swing.JTextField..." and I can't seem to get it working. I've tried reading the tutorial on the Java site but I only found info about changing the editor to something like a combo box or a checkbox... nothing about having it display a text field from the start. Can anyone help? Thanks!
17 years ago
Ah, I see. I actually did that for displaying and updating the data, because otherwise it would've been repeated at least 5 times in the code. It makes sense to keep everything separate, it makes it cleaner too.

I was actually going to have both a "save as" and a regular "save" option to give the user both options.
17 years ago
Thanks, I'll try that! Right now I just have the save stuff in my ActionPerformed method, so when they hit the save button it make the file chooser pop up and everything. So basically, just move the actual save code into a method? How would I check to see if a filename is available? I was trying to figure that out but I have no idea.

And sorry about my ame, I noticed just after I posted that there were requirements so I changed it.
17 years ago
Hi, I'm new here and I have a question that I've been trying to figure out for awhile now. I'm working with saving files and stuff using a GUI and I was wondering how you could just have a "Save" button (like in MS Word, there's a "Save As..." and a regular "Save" menu item). I currently have a Save As option in my program but it would be cool to just have a regular "Save" option so you just have to click that and it uses the current filename if there is one, or otherwise it pops up a file chooser. Thanks for any help!
17 years ago