java

How to "do something" on Swing component resizing?

I've a class which extends JPanel. I overwrote protected void paintComponent(Graphics g). There is a variable which has to be recalculated when the panel's dimensions change. How do I do that in a proper way? Thanks in advance ...

Buffered vs non buffered, which one to use?

I am sorry if this is a duplicate but I was not able to find a definitive answer to what is the best practice for each type. I would like to know what the appropriate conditions are that define when to use BufferedReader vs FileReader or BufferedInput/OutputStream vs FileInput/OutputStream? Is there a formula of sorts that will always ...

Scala - Java interop: can Scala emit enums in bytecode for Java to consume?

I have a project that is mixed Java/Scala, it is Java GUI code that makes use of a Scala library. Is there a way to write Scala code such that it will emit Java enums on compile time? The approaches I tried so far (sealed case classes, extend Enumeration) seem to generate normal classes which makes working with them from Java much hairie...

Subclipse problem: running .java file as Java application

After checking out code for the first time from a repository into Eclipse using the Subclipse plugin, I've found that I am not able to run Java applications anymore. Usually when I right click in the text editor window and select "Run As", I see the option to "Run as Java Application". Now, however, all I see is "Run on server." Is th...

Suggestions for uploading very large (> 1GB) files

I know that such type of questions exist in SF but they are very specific, I need a generic suggestion. I need a feature for uploading user files which could be of size more that 1 GB. This feature will be an add-on to the existing file-upload feature present in the application which caters to smaller files. Now, here are some of the opt...

Java reading standard output from an external program using inputstream

Hello, I am trying to develop a class that reads the standard output of an external program(using an instance of Process, Runtime.getRuntime().exec(cmdLine, env, dir)). The program takes user inputs during the process, and would not proceed until a valid input is given; this seems to be causing a problem in the way I am trying to read it...

Can I use an included third-party jar outside of ColdFusion

We have ColdFusion MX7 which uses ICEBrowser behind the CFDOCUMENT tag to render HTML. We would like to use ICEBrowser for some other Java work but it has been discontinued and seems like a bad purchase. I could simply link to the ICEBrowser jars in the ColdFusion directory but that seems like it may be a licensing issue? Those are th...

Accessing the JavaScript Table DOM in a Java Servlet

I want to write reusable code that takes an HTML table from a JSP and converts it to Excel format to be exported to the user. I want to take advantage of the HTML DOM Table Object rather than parse the HTML in Java to extract the same information. The biggest advantage to this would be inspecting each cell for checkboxes, buttons, etc....

Swing: How could I use JTree with JTextPanes as nodes?

JTree uses DefaultTreeCellRenderer as cell renderer. This class is a subclass of JLabel. I want to use JTree with more complex elements than JLabel, such as JTextPane. Problem is: I can't subclass DefaultTreeCellRenderer, because it would still be a JLabel. Writing an own TreeCellRenderer is too complex. Why? Because: DefaultTreeCell...

Loading and saving a tile based game in Java. XML or TXT?

Hi all. For some time I've been making a 2d tile based sim game, and it's going well! Thanks to this site and its kind people (You!), I have just finished the path-finding part of the game, which is fantastic! THANK YOU!... Anyway, to the question. At present, the test level is hard-coded into the game. Clearly I need to re-work this. M...

What is the fastest method for reading from a text file in Java?

I currently use: BufferedReader input = new BufferedReader(new FileReader("filename")); Is there a faster way? ...

Maven Run Project

Is there a Maven "phase" or "goal" to simply execute the main method of a Java class? I have a project that I'd like to test manually by simply doing something like "mvn run". ...

Why does reading a file into memory takes 4x the memory in Java?

I have the following code which reads in the follow file, append a \r\n to the end of each line and puts the result in a string buffer: public InputStream getInputStream() throws Exception { StringBuffer holder = new StringBuffer(); try{ FileInputStream reader = new FileInputStream(inputPath); BufferedReader br = new Buffe...

Best API/LIB for encoding/decoding base64/quoted-printable in Java

Possible Duplicate: Decode Base64 data in java Thanks to everyone in advance, I am aware of http://commons.apache.org/codec/api-release/org/apache/commons/codec/binary/Base64.html etc, can anyone point to me another option preferably one that does not require me to use external libraries. Thanks, Sam ...

Adding a WCF reference to a j2me project

I have a wcf serivce I want to consume from a j2me application (blackberry). I have been going crazy since the tools that work fine for the j2SE used for consuming web services do not work all that well for j2me. At least not with my service. I found a useful tutorial at http://www.netbeans.org/kb/60/mobility/mobile-dilbert.html Whi...

How to replace URLs of links using Java HTMLParser (org.htmlparser)

I am using htmlparser (htmlparser.org) to re-write all the link's in a input String. All i need to do is iterate over all the link tags (<a href=...), that appear in the input String, grab their value, perform some regex to determine how they should be manipulated, and then update the link's href, target and onclick values accordingly. ...

Concurrent Modification Exception

I'm currently working on a multi-threaded application, and I occasionally receive a concurrently modification exception (approximately once or twice an hour on average, but occurring at seemingly random intervals). The faulty class is essentially a wrapper for a map -- which extends LinkedHashMap (with accessOrder set to true). The clas...

Disable download for a single dependency

I am downright annoyed because the Quartz release I'm importing does not have a proper POM file deployed (maven repo). Therefore maven dutifully tries to download it on every build. Downloading: http://repo1.maven.org/maven2/opensymphony/quartz/1.6.3/quartz-1.6.3.pom I'd like to skip this step but without going completely offline sin...

Tomcat security constraint for valid user

I'm trying to protect a resource in tomcat so that only "valid users" (those with a valid login and password in the realm) can access it. They do not necessarily belong to a group in the realm. I have tried with many combinations of the <security-constraint> directive without success. Any ideas? ...

java how to do a sender thread

Hi all, I was told that any data going out over an output stream (i'm using tcp/ip in my case) could block. In that case, I would not want to halt the application by having to wait for data to go out. I need a model of how to do this. I need to send message objects over this stream. I am thinking I need a blocking queue that conta...