java

How can I correctly remove an AjaxSelfUpdatingTimerBehavior from a component in Apache Wicket?

I'm having trouble with adding and then removing an AjaxSelfUpdatingTimerBehavior in Apache Wicket. The behaviour gets added okay but then as soon as I remove the behavior I get a "Page Expired" come up in the browser very soon, I guess because the removal wasn't clean. My set up is basically a label which starts changing by timer, and...

Swallowing exception thrown in catch/finally block

Usually I come across situations where I have to swallow an exception thrown by the clean up code in the catch/finally block to prevent the original exception being swallowed. For example: // Closing a file in Java public void example1() throws IOException { boolean exceptionThrown = false; FileWriter out = new FileWriter(“test...

JMenuBar at the top in MacOSX

In the Java Desktop Application template used by Netbeans, a menu bar is created with JMenuBar and JMenuItems. How can I get that bar displayed at the top, where menu bars are displayed in MacOSX instead of in-window, like in Windows? ...

Java add chars to a string

I have two strings in a java program, which I want to mix in a certain way to form two new strings. To do this I have to pick up some constituent chars from each string and add them to form the new strings. I have a code like this(this.eka and this.toka are the original strings): String muutettu1 = new String(); String muutettu2 = new S...

How to get name of color using Color Chooser in java

I want name of the color which is selected from Color chooser but now it is returning me the R,G,B Values. I want the name of the color for further use.Can anybody help me? ...

bug thread handling in java

public class Test extends Thread{ public void hello(String s){ System.out.println(s); } public void run(){ hello("I’mrunning..."); }//endofrun() public static void main(String [] args){ Test t=new Test(); System.out.println("always first"); t.start(); System.out.println("always second but...

Capturing text from controls on a Java Applet

Is it possible to capture the text of say a Edit Box or Label control on a Java Applet? In a more traditional Win32 program this can be accomplished using FindWindow, FindWindowEx together with things like GetWindowText. I have investigated with WinSpy but the Java Applet is just one large window with no children. I am wondering if th...

Download manager in Java

I need to several some huge files (several gigs) from Java via FTP/HTTP. Is there a ready library (java / command line tool) to facilitate the download? Some obvious requirements are: Multi-connection download - should be able to open several connections to the server to accelerate the download (like FlashGet/GetRight/...) Resume a dow...

Java reflection: How can I retrieve anonymous inner classes?

Hello, everyone! I have an anonymous inner class inside another class (SomeClass). Both SomeClass.class.getClasses() and SomeClass.class.getDeclaredClasses() return empty arrays. I couldn't find some hints on this in Class' Javadocs. Can anonymous inner classes be retrieved using reflection in some way? What else are notable differe...

In the 13 years that Java has been around, are there any specific examples of backward incompatibilities?

It has been thirteen years between the initial public release of Java 1.0 (1996) and the current stable release 1.6.0_16 (2009). During those thirteen years the following notable releases have been made: JDK 1.0 (January, 1996) JDK 1.1 (February, 1997) J2SE 1.2 (December, 1998) J2SE 1.3 (May, 2000) J2SE 1.4 (February, 2002) J2SE 5.0 (...

Spring - How 'multiple' AOP behaviors to sevices are resolved?

Hello, I want to know that whether we can apply 'multiple' AOP behaviors to our service classes or not? Lets just say, i do this to my BankServiceImpl class: @Transactional on top of one of the method, accountTransfer(), and and some custom <aop> pointcut on the execution of another method someOtherMethod(). Then will Spring be able...

Strange Java cast exception. Why can't I cast Long to a Float?

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Float Why is this a problem? The numbers that I'm trying to cast are decimals in the domain [-10.0, 10.0]. They start out as Object instances returned using JFormattedTextField.getValue(). But they must be converted to floats. stack trace: Exception in thread "AW...

Spring: Getting FactoryBean object instead of FactoryBean.getObject()

Short question: If I have class that impelemnts FactoryBean interface, how can I get from FactoryBean object itself instead of FactoryBean.getObject()? Long question: I have to use 3-rd party Spring based library which is hardly use FactoryBean interface. Right now I always must configure 2 beans: <!-- Case 1--> <bean id="XYZ" class="F...

Invalid memory access of location with Rococoa

I've been trying to code a simple screenshot application using rococoa (java to osx cocoa api library), and managed to get as far as actually taking the screenshot, and then saving it to a file. Unfortunately, once in a while, the application fails with an 'Invalid memory access of location...' error. I'm assuming this is due to somethin...

How does transaction propagation work when using Open Session In View?

I'm really confused about transaction propagation in Spring with Hibernate. I use Spring @Transactional annotations on my service layer methods. Some are marked as 'read-only=true'. If one of my read-only service methods calls a method that is not read-only, how can I deal with this? I'm thinking I can mark all my read-write methods to ...

How to create a bot for gtalk that search for online help Java?

I have idea that for people who use gtalk especially for developers, how to write a bot that recieve question from one developer and ask other online developers for help based on their programming skills? Bot added by the user to gtalk and user will gave his/her skills at first time Then if someone ask a question application will sear...

Java DataAware components

Is there any free data aware components for java, like good old Jbuilder components? For example data aware visual grid component where you can add, modify, commit data to database? ...

Java Swing: multiple windows

I'm new to GUI programming, but need to create a multiple window GUI. Does anyone know of any good tutorial online or could you please show a simple code that will launch 2 windows? ...

Print to specific printer (IPP URI) in Java

Is there any way in Java to print to a specific IPP printer? All of the sample code and tutorials I've found focus on how to print a particular type of document, using something like the following: DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT; PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSize...

How do I say 5 seconds from now in Java?

I am looking at the Date documentation and trying to figure out how I can express NOW + 5 seconds. Here's some pseudocode: import java.util.Date public class Main { public static void main(String args[]) { Date now = new Date(); now.setSeconds(now.getSeconds() + 5); } } ...