There is a written program with Swing standards library, to change one visual component, the successor JComponent decided to simplify his life and use the built-in idea plug-in, created a new -> GUI form, set up a component design (two files, one java, another XML with form markup) , but here’s how to use this component in the mind’s application I won’t apply, how to make the program draw this component. It should be placed in the program on JPanel. Tell me, maybe you should redefine a specific method, or in the constructor, specify the drawing in some way. Or is it initially a dead-end path, and when using the GUI Form, you need to write the entire program, and a separate component is impossible?

    2 answers 2

    After you have marked out the form and generated the java file, you should go to this file and add after the description of the extends class and the class you need. For example extends JPanel . After that you can create an instance of this class and treat it as you would with a JPanel . For example, insert into another panel of your form.

    • I wrote extends JComponent, the program doesn’t compile the problem, but the fact that components are added to a class when building a GUI form via intellij, but they are not displayed in any way, it is different from the position, a basic panel is created when building a GUI form. which all components are placed. so, it’s not the component itself that should be added to the base program, but this very basic panel, in this case everything is normally visible, although you will have to rewrite a little bit - Yury Yakhnitsa
    • @Yuri Yakhnitsa can elements be added, but the component itself does not correctly determine its size when outputting to a form and appears with minimum sizes? What if you try to explicitly set sizes with setBounds? - GreyGoblin
    • As an option, the problem is in size, or in coordinate, maybe it is built outside the application. The fact is that I specially compiled all the java code for building the application, copied it into a new class and everything is perfectly drawn in this class, and in a class where all this code is created nothing works. I already broke my head how to work with it in normal mode. If there is a minimum tutorial to go through creating forms in the idea, there will be less questions. - Yuri Yakhnitsa

    The question is decided by reading this link how to get the code based on the GUI Form

    the whole point is that Idea generates an internal JPanel on which all elements are placed, just in the designer it is worth adding this panel to our new component (respectively inheriting from JPanel or JComponent) and to everything else in the designer it is already possible to change the headers of all components, install listeners and stuff, I nakyryalsya but thank God figured out, now you can use the form editor at your discretion