Adam Price

Ranch Hand
+ Follow
since Nov 11, 2005
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 Adam Price

Craig Wood wrote:



That is very helpful - thank you. I am using netbeans* and based on your tip, I added
as pre-creation code on the main panel in which the JTable resides. Then I used the Table Contens ->Columns -> renderer option to set the custom renderer as dtcr. That works for the column data, and I think it points me in the right direction to figure out how to center the column headers as well.

Thanks again!

-Adam


*I know that isn't a good way to learn Java, but I am not trying to learn java - I am trying to write a program that will help me with my graduate school research on chemical adsorption isotherms.
12 years ago

Don Kiddick wrote:You don't necessarily have to do that. DefaultTableCellRenderer *extends* JLabel so you can do :




Sorry to drag up an ages-old post, but could someone help me understand how this advice is implemented? Where do I declare the DefaultTableCellRenderer and how do I actually apply it to cells in the jTable?

Thanks,

Adam
12 years ago

Paul Clapham wrote:Yes, JTable would be a good starting point. You get the data from its table model once the user clicks the "OK" button or whatever they do to indicate they have finished inputting the data.



What is the method call for that? I found all the .getComponent methods, and all the methods for getting information about what is currently being edited (row#, col#, etc) but not for the cell contents.
12 years ago
I am building a GUI to lay over a script that I have already written for calculating some chemistry "stuff."

The crucial input is a list of solutes with a few associated parameters. Like so


The whole point of the GUI s to collect this information from the user, run a few calculations and return a formatted text list.

The code as shown has 3 rows (solutes). Users may want to run the script with from 2-8 solutes. I would like some sort of interface that displays the parameters a little more clearly than the form above.

I have been thinking about using a jTable (the rest of the GUI is swing-based) but I can't figure out how to get the contents back from it. Is jTable the way to go? If not, what is? If so, how to I get that user input out?


Thanks,

Adam
12 years ago

Originally posted by Rusty Smythe:
This is exactly why exceptions should not be hidden and ignored.

Yeah - the code in question was pre-written code that we were to use in an intro to java course that I am taking at my local Community College. The instructor explained to me that he had written it that way because the class doesn't cover exception catching - that comes in the second semester, so he wanted the only possible outcomes to be full success or null returns.
We weren't expected to give the level of detail in the feedback that I wanted to give, but I have a stick in my....ear about non-helpful error messages. I spent way, way to much time getting it to work right, but in the end it does (Thanks again EFH!). It makes no difference to my grade, but it is very satisfying to have it behave in an intelligent way.

15 years ago

Originally posted by Ernest Friedman-Hill:
You want to create a PrintStream wrapped around a ByteArrayOutputStream, set System.out to that (saving the old one,) call your naughty API, use "new String(baos.getByteArray())" to make a String out of the ByteArrayOutputStream, test that String, and then, in a finally block, put the original System.out back. Make sense?



Hey, that worked! And I learned about B.A.O.String's and PrintSterams in the process. Cool, thanks!
15 years ago
(Apologies if this belongs in beginner - I know it is not terribly advanced, but it is not for rank amateurs either. Please move if necessary)

I am working with a supplier class that improperly deals with exceptions. Instead of throwing them, it catches its own problems and prints them to system.out.

(For example - one of the things it does is parse a file at a given URL. If it can't find the URL, it will generate either a UnknownHostException or a FileNotFoundException, depending on where it breaks. It prints either one to System.out.)

I would like to somehow grab those exceptions and use them as tests in my client class - so that if the file loading fails, I can tell the user which kind of problem my supplier class encountered.

I know I can use System.setErr and System.setOut to redirect that output to a Printstream. But how can I test what was recently added to it.

My desire goes like this in imagino-code:

myPrintStream.flush() //To clear it
parseFileAtURL( http://www.javaranch.com );
if (myPrintStream.lastAddition().contains( "UnknownHost"))
{ myWindowPrintMethod( "The URL you gave was not from a known host.") }
else if ( myPrintStream.lastAddition().contains( "FileNotFound") )
{ myWindowPrintMethod( "That file could not be found") }
else { continueOnWithExecution() }

How could I achieve this general idea? I know the good thing to do would be to change the supplier code but I am curious about how I could deal with it without doing so.
15 years ago

Originally posted by Jeremy Bernard:
I've been trying to find a good online Java school, because after a few books and tutorials, most don't seem to help much..

I've heard to take the Sun Certification exam, but doesn't that require you already know Java, or will it teach you from scratch?

Any help finding a good school "online" would be greatly appreciated..



Depending on your state, you may be able to find a good deal taking it from a community college online. I am going to take a java course from North Seattle Community College online over the summer - in-state tuition is $71 per credit. (The java course is 4 credits) For that I get hand-holding, step-by-step assignments and a discussion forum full of other students doing exactly the same assignments.
15 years ago

Originally posted by Marilyn de Queiroz:
Correct.



Sooo.....about that last cattledrive assignment I sent in...*shuffle*...there's one little change......
15 years ago

Originally posted by Marilyn de Queiroz:
The intent of prohibiting return in the middle of the method is to prevent the very thing you are trying to do, i.e. create more than one exit point to the method.

Reasoning: Using "return" in the middle of a method makes it difficult to later break the method into smaller methods. It also forces the developer to consider more than one exit point to a method.



So even the way I originally wrote it is in bad form, then. Am I right that it would be preferable to have:

[ April 28, 2006: Message edited by: Adam Price ]
15 years ago

Originally posted by Jim Yingst:


Does that answer your question? I'm not sure how it would relate to the earlier part of this thread.


It relates because Marilyn pointed out that the style guide says [bold]return[/bold] shouldn't be in the middle of a method, and I was wondering if there was anything else I could substitute for return that would maintain the spirit of te original question.



-Adam

p.s.: Jim - you might enjoy these
15 years ago

Originally posted by Marilyn de Queiroz:
<pre>3 - Coding
3.1 - Constructs to Avoid
Never use do..while. examples and reasoning
Never use "return" in the middle of a method. (reasoning)

</pre>



Is there anything besides "return" and exceptions that would prevent the completion of a method?
15 years ago
If I a method that does something like this:

I could leave out the "else" and the associated brackets and get the same output. I haven't done so in my assignments because it felt sloppy, but I wonder if the stylists here agree - I can't find it addressed in the style guide.
15 years ago
I found that the degree to which I was expected to anticipate and code for a foolish user was not entirely consistent.

On Hundred, my (accepted) solution would have completely ignored any arguments beyond the first one.
15 years ago
I live between Columbia City and Beacon Hill - must be near your job. I am entirely new to Java, and even to OOP, though, so I can't offer much. I do eat pizza and drink beer though.
15 years ago