can't work on code outside IDEA

Answered

Hi, I'm an university student and I'm running IDEA as my main IDE for Java programming.

My Java teacher uses Eclipse. I still prefer IDEA when I'm working at home, but for some reason the code I write on it doesn't seem to be "compatible" with Eclipse when I'm working on projects that use GUIs. The "UI Designer generated code" doesn't work when I copy-paste it in Eclipse, probably because it contains IDE-specific lines such as

new com.intellij.uiDesigner.core.GridConstraints

On the other hand, I can easily copy-paste the Eclipse-generated code in IDEA, and it works perfectly.

Here's an example of what I'd need from IDEA:

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import javax.swing.JDesktopPane;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class NewJFrame extends javax.swing.JFrame {

    private JPanel contentPane;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    NewJFrame frame = new NewJFrame();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public NewJFrame() {
        setDefaultCloseOperation(NewJFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);

        JScrollPane scrollPane = new JScrollPane();
        contentPane.add(scrollPane, BorderLayout.EAST);

        JDesktopPane desktopPane = new JDesktopPane();
        contentPane.add(desktopPane, BorderLayout.WEST);

        JCheckBox chckbxNewCheckBox = new JCheckBox("New check box");
        contentPane.add(chckbxNewCheckBox, BorderLayout.CENTER);

        JCheckBox chckbxNewCheckBox_1 = new JCheckBox("New check box");
        contentPane.add(chckbxNewCheckBox_1, BorderLayout.SOUTH);

        JButton btnNewButton = new JButton("New button");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                // da qui vengono poi chiamati metodi di altre classi cha contengono dati e permettono di fare i calcoli.
            }
        });
        contentPane.add(btnNewButton, BorderLayout.NORTH);
    }
}

Is there a way to make IDEA generate something like this, automatically? I need code that can be opened with eclipse too, otherwise my work won't be compatible with the pc my teacher will grade it with :(

 

Thank you!

 

 

0
2 comments
0
Avatar
Permanently deleted user

Thanks, it worked.

I'll write what I did, to help others in the same situation:

1)  In IntelliJ : File | Settings | GUI Designer | Generate GUI into: Java source code. Hit "Apply" and close.

2) File | Project Structure | Modules | Dependencies | press Alt+Insert, select "JARs or directories" ...

3) ...  I'm on Linux, so I found the JAR that I needed to add (forms_rt.jar) in the lib folder ( ~/.local/share/JetBrains/Toolbox/apps/IDEA-E ...)

As far as I understand, this library needs to be always included in the build path of your project, regardless of what IDE you're using.

I successfully exported my project with its dependencies to Eclipse and it worked like a charm, so thank you :)

 

0

Please sign in to leave a comment.