简体   繁体   中英

Java Combo Box Diamond Operator not supported in source 1.6

Background

I have developed a program which manipulates data in a database. That however, isn't the problem I have, so I will get straight to the point.

I made a Combo Box on the JFrame called 'Output Re-Formatted Data Files'. The Combo Box should allow users to select a particular month so that the program will do a filtered search for files created in eg February 2016.

The Problem

The options are of course months of the year. The problem I have is, the code in the initComponents() method, for that combo box is underlined in 'error red'!

The error says: "diamond operator is not supported in source 1.6, use source 1.7 or higher".

What I don't understand

I assume that source 1.6 corresponds to the JDK that you have. So surely you only have source 1.6 if you have JDK 1.6. But have JDK 1.8 and Netbeans 8.0.2, so how come Netbeans says I use source 1.6?

I'll be really thankful for anyone who explains this to me, as I've had this problem for nearly 2 months now. I will do more of my own research in meantime too.

Init Components

jLabel4.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
    jLabel4.setText("Month");
    jLabel4.setToolTipText("");

    Month_ComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }));
    Month_ComboBox.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            Month_ComboBoxActionPerformed(evt);
        }
    });

Combo Box Customised Code

I assume that source 1.6 corresponds to the JDK that you have. So surely you only have source 1.6 if you have JDK 1.6. But have JDK 1.8 and Netbeans 8.0.2, so how come Netbeans says I use source 1.6?

Well, not quite - it corresponds to which language version your source code is being compiled as . It's very normal for later compilers to be able to compile as if you only had an earlier version of the compiler, so that if multiple people on a team have different versions, you don't get a situation where one person checks in code that another can't compile.

Just change your project settings to use a source compatibility level of 1.8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM