eclipse-windowbuilder / windowbuilder

Eclipse Windowbuilder
https://projects.eclipse.org/projects/tools.windowbuilder
Eclipse Public License 1.0
79 stars 30 forks source link

Unable to parse source while tring to use JCalender #698

Open londonreturns opened 8 months ago

londonreturns commented 8 months ago
Screenshot 2024-01-26 215721

WindowBuilder not crashing everytime i try to use it. Auto generated code by windowbuilder

package utility;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JScrollPane;

public class TEMPFRAME extends JFrame {

    private static final long serialVersionUID = 1L;

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

    /**
     * Create the frame.
     */
    public TEMPFRAME() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
    }

}
ptziegler commented 8 months ago

line: 13 The type com.toedter.calendar.JDateChooser is not accessible.

That looks a lot like compilation errors in your workspace.

Can you show me what the project looks like? Do you have a module-info.java file which is missing whatever module your custom JDateChooser is coming from?

londonreturns commented 8 months ago

line: 13 The type com.toedter.calendar.JDateChooser is not accessible.

That looks a lot like compilation errors in your workspace.

Can you show me what the project looks like? Do you have a module-info.java file which is missing whatever module your custom JDateChooser is coming from?

i added jcalender in module-info.java file, and it works fine

image
ptziegler commented 8 months ago

Alright then... this is the example I've set up.

I have the project ModularProject1, with a stub class JCalendar:

package test.jcalendar;

import javax.swing.JPanel;

public class JCalendar extends JPanel {
}

and the module-info.java:

module jcalendar {
    requires java.desktop;

    exports test.jcalendar;
}

image

This class is used in a separate project called ModularProject2, where the JCalendar is used by the class MainFrame:

package test;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import test.jcalendar.JCalendar;

public class MainFrame extends JFrame {

    private static final long serialVersionUID = 1L;
    private JPanel contentPane;

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

    /**
     * Create the frame.
     */
    public MainFrame() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.add(new JCalendar());

        setContentPane(contentPane);
    }

}

and the module-info.java:

module ModularProject2 {
    requires java.desktop;
    requires jcalendar;
}

image

Opening the MainFrame class with the Design editor works without problem...

image

This tells me that there is no issue with how WindowBuilder handles the module system. Which makes be believe that there is something wrong with your projects and I therefore need to know what your workspace looks like, if you want me to help you.

As a slightly different question: What steps do you take that cause this error? Because the code snippet you show in your initial post doesn't reference the JDateChooser class and should open on its own.

vanquanle commented 1 month ago

image lỗi này là sao vậy ạ

ptziegler commented 1 month ago

@vanquanle

See:

line: 13 The type com.toedter.calendar.JDateChooser is not accessible.

That looks a lot like compilation errors in your workspace. Can you show me what the project looks like? Do you have a module-info.java file which is missing whatever module your custom JDateChooser is coming from?

i added jcalender in module-info.java file, and it works fine image

You're likely using Java modules, so you either need to add jcalendar to your module-info.java file, or get rid of this file alltogether if you don't really need modules.