java

Java: Handle logoff or shutdown on Windows and Linux

Is there a way for a Java GUI application to respond to system shutdown or logoff events, other than to use JNI? (On Windows, the JNI would use WM_QUERYENDSESSION, on Linux?) The method should allow the program to prompt users to save, etc., and then continue the logoff process. ...

throws Exception in finally blocks

Is there an elegant way to handle exceptions that are thrown in the a finally block? For example: try { // Use the resource. } catch( Exception ex ) { // Problem with the resource. } finally { try{ resource.close(); } catch( Exception ex ) { // Could not close the resource? } } How do you avoid the try/catc...

Best way to deploy a Java application on a cluster of servers?

I have a cluster of 32 servers and I need a tool to distribute a Java service, packaged as a Jar file, to each machine and remotely start the service. The cluster consists of Linux (Suse 10) servers with 8 cores per blade. The application is a data grid which uses Oracle Coherence. What is the best tool for doing this? ...

Flex 2D graphics learning path for Java/GWT developer?

I have been developing with Java for several years and last six months I have been building GWT based application. But I have almost no Flash or Action Script experience and I would like to try out some hobby programming with Flex. Especially 2D graphics and image manipulation would be interesting topics. Adobe's tutorials for Java deve...

Which Java Web Framework fits best with Google Guice?

I'm planning to start on a new project and am looking at the current state-of-the-art Java web frameworks. I decided to build my application around Guice, and am likely to use a very lightweight ORM like Squill/JEQUEL/JaQu or similar, but I can't decide on the web framework. Which one would fit best in such a lightweight environment? And...

Help with annotations

Edit--@Uri correctly pointed out that this was an abuse of annotations; trying to actually create the menu data itself in annotations is just silly. They are good for binding however, I think I'll stick with using them to link the text data to the methods (the @Menu ("File") portion) since it's more explicit and flexible than reflecting...

How can I provide a custom log4j.xml for different ant tasks?

I have a build file that as part of the build process relies on several taskdefs. These taskdef items (for example, webdoclet and jasper2) use log4j as a logger. Ideally, I'd like to be able to provide a different log4j configuration file for each, but minimally, I'd like to be able to specify which log4j configuration file is used. W...

How to simplify a null-safe compareTo() implementation?

I'm implementing compareTo() method for a simple class such as this (to be able to use Collections.sort() and other goodies offered by the Java platform): public class Metadata implements Comparable<Metadata> { private String name; private String value; // Imagine basic constructor and accessors here // Irrelevant parts omitted...

Test for invertability using Jama.Matrix

I have a program that uses JAMA and need to test is a matrix can be inverted. I know that I can just try it and catch an exception but that seems like a bad idea (having a catch block as part of the "normal" code path seems to be bad form). A test that also returns the inverse (or run in a better O() than the inverse operation) would be...

How can a JComponent notified about the closed event of it's parent J(Internal)Frame?

I want to write a component that monitors other activities, but it's listeners are to be removed when the component's window is closed. I don't want to write this removal code many times, but want the component to handle it itself. (How) can i do it? Thanks! ...

How to select first item in JPopupMenu?

In the past, when one made a JPopupMenu visible it's first item would get selected by default: http://weblogs.java.net/blog/alexfromsun/archive/2008/02/jtrayicon_updat.html Nowadays the default behavior is to pop up the menu without any item selected. I would like create a JPopupMenu with a single item that will pop up selected and cent...

How does one successfully open a Java bug if Sun doesn't respond?

I attempted to open a Java bug last Halloween. I immediately got a response that my submission was accepted, and have heard nothing since. Looking at Sun's web pages, I can't found any contact information where I can inquire. Almost two weeks ago I made a post in the Sun forums in what appears to be the most appropriate area and have ...

Java3D: Tutorials, Projects, General 3D Programming

I've been thinking about playing with Java3D. But first I would like to know if anyone has done much with it? What types of projects have you done and what tutorials/examples/guides did you use to learn it? What are your general thoughts about the API? Is it well developed? Can you program games or do any physical modeling with it? ...

Ant cannot find a class needed by an externally defined taskdef

I am trying to use the axis-java2wsdl ant task to create a wsdl from one of my java classes, but I cannot get the classpath correct. I am using Ubuntu's libaxis-java package which installs axis-ant.jar in $ANT_HOME/lib and axis.jar in /usr/share/java. The interesting parts of my build.xml look like this: <property name="library.dir" v...

Java Scientific Packages similar to SciPy?

I've been looking around the internet for a Java scientific package that is "similar" to Scipy. The only thing I have really found is JScience but it seems not to offer plotting and such. Does anyone know of a good scientific package for Java? ...

Can I get Eclipse File Search to include ivyde jars?

The Eclipse File Search dialog doesn't seem to be playing nicely with my ivyde (2.0.0beta1) dependency jars. That is, my ivyde brings some-dep.jar/some-dep.zip (class/source), but I don't see any way to get my file search (ctrl+h search) to include these resources when searching for text -- so if MAGIC_FLAG appears only in the Magic clas...

problem with unicode characters.

Hi, I have problem with unicode.. i have multi language project. when i enter the data in local language, in access the data is storing something like this as " ಅಮ್ಮ" but i want those characters of local language to be seen at the bach end.. could you please suggest me ?? am using java, windows vista, and ms-access.. I had set ...

How can I travese to a next / previous page in a swing GUI

Hi All, I am new to Swing. I am trying to develop an application using Swing. I have managed to create the first page of my application. Now what I want to do is to traverse to a new page, using the next button. But am not able to find a way to do it using Swing. Also, if I click the previous button, would I be able to get the data that...

Can you tell on runtime if you're running java from within a jar?

Hi, I have an application that some of my users run from Eclipse, and others run it by using a jar file. I want some actions to be done when running from within the jar, but I don't want them to be done when running from Eclipse. Is there a way to know on runtime whether the current application is running from within a jar? Thanks! ...

[Java] How to extract the file name from a file URI and create a link for the same?

My problem is :: From a string like "/usr/folder1/folder2/filename.ext" I have to extract out file name only for display (filename.ext only). My question would be how should I do it? Splitting on "/" and taking the last element is one way but doesn't smell nice to me. I have to create a hyperlink which uses URI of the file as the de...