Help coderanch get a
new server
by contributing to the fundraiser

Andy Nimmo

Greenhorn
+ Follow
since Mar 30, 2003
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 Andy Nimmo

Jeff,

Have you tried using the ScrollPane method

setScrollPosition( int x, int y )

You can use it with the Point instance that you've already created in your example code:

setScrollPosition( Point p )

If I had the time I would try this out myself and give you a definitive answer. Try dropping the references to viewPort as well.

Might also be worth getting the scroll position BEFORE you remove the object whose scroll position you're interested in, just a thought.

So try this:



Hope there's something useful to you there.

Andy.
19 years ago
Liat,

The second issue you mentioned about the process not dying along with your Java process can be overcome by manually killing the process in your exit code.

I find it's always good practice to have a handle available on the windowClosing event of your GUI. You don't have to put any special code inside this event capture block but it means that you can tidy things up ni the event of your Java app closing.

For example:

I always create an internal class which handles these Window events and then add an instance of the internal class as a registered listener for the parent class.



The code isn't perfect, it's been a long time since I worked with Java and I'm a little rusty!

With regards to your second problem I'm not 100% sure what the actual problem you feel that you have is. There is nothing wrong with using an exception to handle a certain situation. In fact that is why they exist.

An alternative would be to create a new Thread and pass it a Runnable object which spawns the external help file viewer. The runnable object can then be monitored to see if it is still running or not.

Sometimes though, it's just easier and cleaner to wait for an exception liek the one you get already and then deal with things as appropriate.

Hope some of this helps,

Andy.
19 years ago
Alternatively Joe, and assuming your JDBC driver supports this you could use the following code snippet:



It's not a very nice way of doing it but it's one of the few ways you can do what you're asking. I've given up trying to find a nicer way of doing this.

Andy.
Paul,

That's not strictly true. Although exceptions are the best way of dealing with an occurance of a showstopping situation there are other ways to do things.

In this example Nicolas wants to just check if the connection is still alive and well which can be done quickly and easily without waiting for an exception to be thrown.

Have a look at the following code which I am using in one of my database access classes:



This simple example checks to see if the connection is alive before it attempts to send a Query. If the connection isn't alive then it attempts a single re-establishment of the connection before failing.

Hope this helps.

Andy.
I don't think the problem you are describing is really a matter of platform independant as most people you ask would not believe different hardware running the same software as being different platforms. You did however mention that the problem was OS linked yet the only OS that you mention in your post was WinXP Pro, with your wording suggesting to me that all the notebooks you used had the same OS installed.
Have you tried running your code on a Linux box? What does it look like then? That would answer your platform independant question.
Also, have you tried using any other Swing Apps on the aforementioned notebooks? What was the outcome?
In the past I have had similar problems which were related to how I was laying objects out and setting their attributes, differences between the JRE's you mention may simply be down to minor changes in how certain events / situations are handled at Runtime.
As Brian asks, what L&F are you using? Have you tried a different L&L? Ho does that appear across the different systems you describe?
20 years ago
Richard,
At what point in your code are you calling the validate( ) method? Also, which components validate( ) method are you calling?
Maybe post a little code in a reply so we can see what you're doing easier.
Cheers,
Andy.
"I Code, Therefore I Am"
20 years ago
That's spot on!
Thank you very much, got all sorts of wonderful things happening now!
Cheers,
Andy.
"To Err is human but to really foul up requires a computer"
20 years ago
I've developed a small app which handles the execution of a number of external applications and holds them in threads to which it sends heartbeats to ensure that their runtimes do not idle.
What I need to implement now though is to move the mouse cursor to generate screen update events as if a user was sat at the PC moving the mouse.
Is this possible and how would I go about doing it?
Cheers,
20 years ago
Thanks guys.
Both are kind of what I was expecting although I'd overlooked the instanceOf method call.
The reason I asked this question wasn't simply down to my example situation as I have in the past created some generic methods which could accept a number of different objects and act accordingly. I just hate long windedness and do my best to make things clear aond concise, sometimes to overload a method can result in a large quantity of highly similar code which cant be refactored into a second method call without resulting in yet more code.
I have what I need now.
Cheers again,
Andy.
20 years ago
I have a method to which I expect have one of two possible Classes sent to at any given time.
I could just create two forms of this method however this is something I come across on a regular basis and have always wanted to know if it is possible to do this.
I have a class which I cast to type Object then pass it to a method call. In the method body I want to cast this object back to it's previous type.
For example:
ContactsList -> Object -> saveToFile( theObject )
theObject -> ContactsList
Hope this makes sense.
Can anyone help? I've had a look at Java Reflections but I'm having a bad day and I'm unable to decipher what's in there and apply it to my situation.
All help is greatly appreciated.
Cheers,
Andy.
*****************************************************
Here I Stand, Alone, Left To Face The Coming Darkness
Bring it on!!
*****************************************************
[ February 19, 2004: Message edited by: Andy Nimmo ]
20 years ago
I think this needs to be moved to the Performance forum as it's a more performance related question!
Andy.
20 years ago
Bala,
The File class has two methods called canRead( ) and canWrite( ).
I beleive that if you use either of these when they point to your File in question then they will tell you if there is any process maintaining a lock on it.

You might have tried this already, let me know if it solves your problem or not!
Andy.
20 years ago
From what I can make out from the code you placed in your post you don't actually do anything with the InputStream and OutputStreams which you create. This means that although you get a handle on the data you want you don't actually access it in any useful sense.
What you need to do is to tell your InputStream "input" to read in wahtever data is contained within the file and then place that data into your JTextArea.
The opposite goes for your save dialog, you need to output the data contained within your JTextArea and write it to the file, the details of which has already been returned by your JFileChooser object. Although I can't actually see a FileOutputStream created anywhere with which to save the file to disk.
For your "Open" button (Assuming the data is saved as a JTextArea object):

Now for your "Save" button:

I'm possibly missing something with only having a small code sample, it would be much better if I could have a copy of the whole class.
Hope this helps!
Andy.
20 years ago
I'm having a problem with an application that i'm currently writing. I'm using Sockets to connect between a client and server. With a new Thread running for each client Socket connection.
The problem is that my "readObject( )" method is in a "while" loop as seems to be the standard way of doing things as object will arrive at this Socket at random intervals.
The snippet of code is as follows:

Without wanting to go into too much detail with regards to the code surrounding this try block the problem basically comes down to the fact that I'm ignoring IOExceptions and it all works except it takes a very long time to register that a new Object has arrived at the Socket.
Obviously this is because that Thread is tanking along within its loop but I was under the impression that a Socket operation such as this was blocking and as such would only continue when it was able to complete.
Can anyone suggest a better way of achieving the above result but without the long delays I'm experiencing? there is no other code in this "while" loop.
Any help appreciated!
Andy.
- I drink therefore I am
20 years ago