java-7

Is this a Swing Java 7 rendering bug?

牧云@^-^@ 提交于 2019-11-27 06:47:51
问题 I made a simple Swing application. But the rendering behaves buggy. Have I done anything wrong or is it a bug? It's simple a small JFrame with a textfield, button and an empty list. If I first resizes the window horizontally and then type in the textfield, the button suddenly disappear. Here is my code: public class App extends JFrame { public App() { JTextField messageFld = new JTextField(); JButton saveBtn = new JButton("Save"); JPanel inputPanel = new JPanel(new BorderLayout()); inputPanel

Java 7 Automatic Resource Management JDBC (try-with-resources statement)

感情迁移 提交于 2019-11-27 06:40:54
How to integrate the common JDBC idiom of creating/receiving a connection, querying the database and possibly processing the results with Java 7's automatic resource management, the try-with-resources statement? ( Tutorial ) Before Java 7, the usual pattern was something like this: Connection con = null; PreparedStatement prep = null; try{ con = getConnection(); prep = prep.prepareStatement("Update ..."); ... con.commit(); } catch (SQLException e){ con.rollback(); throw e; } finally{ if (prep != null) prep.close(); if (con != null) con.close(); } With Java 7 you can go for: try(Connection con

How to install java jdk 7 on Snow Leopard

倾然丶 夕夏残阳落幕 提交于 2019-11-27 06:26:35
My Mac currently is running Snow Leopard (10.6.8), and I would like to develop with Java 7. I downloaded the Java 7 OS X installer from Oracle's website , started to run it. Unfortunately, I was immediately greeted with a message that said the installer is supported only on OS X Lion (10.7.3). Is there any way I can get Java 7 on my machine with Snow Leopard? I am not buying a new OS just to upgrade my Java. I googled around some, but I am not finding much. I'm hoping I can find some help here. Thanks. Use Pacifist from http://www.charlessoft.com/ to open and install the 'JDK 7 Update X.pkg'

How to set IntelliJ IDEA Project SDK

萝らか妹 提交于 2019-11-27 06:19:51
I just installed IntelliJ IDEA and when I try to create my first Project it asks for me to set up the Project SDK. When I click on "JDK" it asks for me to select the home directory of the JDK as shown in this image. I'm having trouble locating where it is. BevynQ For a new project select the home directory of the jdk eg C:\Java\jdk1.7.0_99 or C:\Program Files\Java\jdk1.7.0_99 For an existing project. 1) You need to have a jdk installed on the system. for instance in C:\Java\jdk1.7.0_99 2) go to project structure under File menu ctrl+alt+shift+S 3) SDKs is located under Platform Settings .

Drag and drop differences between JDK1.6 and JDK1.7

可紊 提交于 2019-11-27 06:14:14
问题 Does anybody know about differences in the drag-and-drop behavior between JDK1.6 and JDK1.7 ? I encountered a difference (illustrated below) when drag-and-dropping an URL from a browser onto an application which needs to support JDK1.5, JDK1.6 and JDK1.7 . I am now wondering whether other differences exists and if they are documented somewhere. The different behavior I encountered is when drag-and-drop an URL from a browser (not from the address bar but from the page) by click-and-drag the

Differences in auto-unboxing between Java 6 vs Java 7

♀尐吖头ヾ 提交于 2019-11-27 06:10:59
I have noted a difference in auto unboxing behavior between Java SE 6 and Java SE 7. I'm wondering why that is, because I can't find any documentation of changes in this behavior between these two versions. Here's a simple example: Object[] objs = new Object[2]; objs[0] = new Integer(5); int myInt = (int)objs[0]; This compiles fine with javac from Java SE 7. However, if I give the compiler the "-source 1.6" argument I get an error on the last line: inconvertible types found : java.lang.Object required: int I tried downloading the Java SE 6 to compile with the native version 6 compiler (without

How do I use JDK 7 on Mac OSX?

我的梦境 提交于 2019-11-27 06:06:09
I would like to use the WatchService API as mentioned in this link: http://download.oracle.com/javase/tutorial/essential/io/notification.html After reading around, I found out that WatchService is part of the NIO class which is scheduled for JDK 7. So, it is in beta form. It's fine. http://jdk7.java.net/download.html has the JDK which I downloaded and extracted. I got a bunch of folders. I don't know what to do with them. Then, I read around some more and found that some nice group of people created JDK 7 as a binary so someone like me can install it easily. It is called Open JDK: http://code

Double brace initialisation (anonymous inner class) with diamond operator

纵饮孤独 提交于 2019-11-27 06:02:36
问题 I am wondering why the second map declaration (using the diamond operator) does not compile when the first one does. Compilation error: error: cannot infer type arguments for HashMap; Map map2 = new HashMap<>() { reason: cannot use '<>' with anonymous inner classes where K,V are type-variables: K extends Object declared in class HashMap V extends Object declared in class HashMap Code: Map<String, String> map1 = new HashMap<String, String>() { //compiles fine { put("abc", "abc"); } }; Map

Application is using Java 6 from Apple instead of Java 7 from Oracle on Mac OS X?

帅比萌擦擦* 提交于 2019-11-27 05:57:54
I am testing my current application with Mac OS X which has Java 7 from Oracle installed. Instead using Java 7 from Oracle, it's using Java 6 from Apple. The default system output of java -version is showing 7 . I tried most of the things mentioned in different sites, but I was unable to fix this issue. JAVA_HOME is also properly set. I am using the Mac only for testing purposes. I really need some guidance on this. When I run it with Eclipse by selecting JRE 7, it runs properly. Thus there is nothing wrong with the application. I am missing something on Mac OS X. My Java system environment

Are Locks AutoCloseable?

随声附和 提交于 2019-11-27 05:44:06
问题 Are Locks AutoCloseable? That is, instead of: Lock someLock = new ReentrantLock(); someLock.lock(); try { // ... } finally { someLock.unlock(); } can I say: try (Lock someLock = new ReentrantLock()) { someLock.lock(); // ... } in Java 7? 回答1: No, neither the Lock interface (nor the ReentrantLock class) implement the AutoCloseable interface, which is required for use with the new try-with-resource syntax. If you wanted to get this to work, you could write a simple wrapper: public class