Ramblings Of a Madman

Yeah, like i would know a good description…

Posts for Tag: java

'OSX Mavericks "You need a Java 6 runtime to run X" error dialog fix'

Ok, so here's the deal: If you upgrade to [OSX Mavericks](https://www.apple.com/osx/preview/), only had JAVA 7 installed, and try to run anything that requires JAVA you will probably get a nice dialog like this one:

All my attempts to make Mavericks use JAVA 7 instead have failed so i tried the next best thing: Install JAVA 6. Since you can't find JAVA 6 for Mac at the [Oracle](http://java.oracle.com) site, you'll have to install it from here: [Java for OS X 2013-004](http://support.apple.com/kb/DL1572).

After installing you'll end up with this following structure at the "/System/Library/Frameworks/JavaVM.framework/Versions" folder:

drwxr-xr-x 11 root wheel 374 29 Ago 14: lrwxr-xr-x 1 root wheel 10 29 Ago 14:58 1.4@ -> CurrentJDK lrwxr-xr-x 1 root wheel 10 29 Ago 14:58 1.4.2@ -> CurrentJDK lrwxr-xr-x 1 root wheel 10 29 Ago 14:58 1.5@ -> CurrentJDK lrwxr-xr-x 1 root wheel 10 29 Ago 14:58 1.5.0@ -> CurrentJDK lrwxr-xr-x 1 root wheel 10 29 Ago 14:58 1.6@ -> CurrentJDK lrwxr-xr-x 1 root wheel 10 29 Ago 14:58 1.6.0@ -> CurrentJDK drwxr-xr-x 7 root wheel 238 29 Ago 14:58 A/ lrwxr-xr-x 1 root wheel 1 29 Ago 14:58 Current@ -> A lrwxr-xr-x 1 root wheel 59 29 Ago 14:58 CurrentJDK@ -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

So you might want to fix the path to the current JDK, so that you keep using the JDK 7 by default (Eclipse users, you know what i mean ;)):

$ sudo rm CurrentJDK $ sudo ln -s /Library/Java/ $ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents CurrentJDK

Another thing you might need to change is the JAVA_HOME environment variable but, since that depends on whatever shell you use, [Google it](https://duckduckgo.com/?q=set+JAVA_HOME+in+bash) ;)

Finally, verify that you are still using JAVA 7 by default:

$ javac -version javac 1.7.0_25 $ java -version java version "1.7.0_25"

Have fun.

JAVA vertical gradient background panel

Recently i had to create a gradient background for one of the panels in our [POS application](http://inforviegas.pt/wp-content/uploads/2010/09/VOS.jpg), so i though i'd share the code.

You need to pass the top and bottom colors of the gradient and also make sure that any panels inside this one are transparent (i.e. setOpaque(false)), otherwise they will paint above it.

import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints;

import javax.swing.JPanel;

public class VerticalGradientBackgroundPanel extends JPanel {

private Color topColor; private Color bottomColor;

public VerticalGradientBackgroundPanel(Color topColor, Color bottomColor) {

this.topColor = topColor; this.bottomColor = bottomColor; }

@Override protected void paintComponent(Graphics grphcs) {

super.paintComponent(grphcs);

Graphics2D g2d = (Graphics2D) grphcs;

g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint gp = new GradientPaint(0, 0, topColor, 0, getHeight(), bottomColor); g2d.setPaint(gp); g2d.fillRect(0, 0, getWidth(), getHeight()); } }

JAVA JScrollPane change scrollbar width or height

It's actually pretty simple. Just do something like this, adjusting to the horizontal scrollbar and/or the height that you want:

yourScrollPcane.getVerticalScrollBar().setPreferredSize(new Dimension(85, Integer.MAX_VALUE));

JasperReports - Unsupported major.minor version 51.0

Just ran into something a bit far fetched: My Jasper reports were not working in VOS, our JAVA Swing application at Inforviegas. It complained with an error along these lines: Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedClassVersionError: CCClient_1334580618412_476658 : Unsupported major.minor version 51.0

The only difference from business as usual was that i changed laptops.

We are using the jasperreports-maven-plugin to compile the reports from maven. In our pom.xml files we always define the maven-compiler-plugin target and source versions of the virtual machine. One would assume that the jasper plugin would use the same version of the maven-compiler-plugin, right? Wrong. It uses the default virtual machine set in your computer. And since i had Java 7 as the default and we are compiling to Java 6, the reports end up with the wrong java version, making them not show in our application.

Hope this helps some people save some time, since i couldn't :)

NonUniqueObjectException- a different object with the same identifier value was already associated with the session

If you are developing in Swing and using hibernate you might - at some point in time - run into this exception: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

What happened, you might ask? Well, turns out that when you close the session that created a given hibernate-managed object, this object becomes "detached" (meaning hibernate no longer has any control over it). So, when you attempt to save or update it in another session, hibernate will complain with that exception, because it can no longer tell which is the "true" version of the object.

The solution(s)? Look inside your code for places where you might be closing the session and take that out. That's the solution in the case where you are using a long session (one that spans the entirety of the application's life). In case you really want to close the session, you might consider using the session's merge() method, which basically merges the fields in both the attached and non-attached instances of the object, and performs an update.

Hope that saves someone half a day of debugging ;)