Java 无法将自定义类添加到IntelliJ GUI设计器中的面板

Java 无法将自定义类添加到IntelliJ GUI设计器中的面板,java,swing,user-interface,intellij-idea,Java,Swing,User Interface,Intellij Idea,我已经为图形绘制创建了一个子类JPanel,并将其添加到调色板中,但是当我试图将其添加到主面板时,什么都没有发生。另外,如果我尝试将其添加为非调色板组件,对话框将关闭并再次打开,要求选择要添加的类。 下面是课程: import javax.swing.*; import java.awt.*; /** * Created by gray on 05.11.14. */ public class PPanel extends JPanel { // Object for the class

我已经为图形绘制创建了一个子类JPanel,并将其添加到调色板中,但是当我试图将其添加到主面板时,什么都没有发生。另外,如果我尝试将其添加为非调色板组件,对话框将关闭并再次打开,要求选择要添加的类。 下面是课程:

import javax.swing.*;
import java.awt.*;

/**
 * Created by gray on 05.11.14.
 */
public class PPanel extends JPanel {
// Object for the class realizing graph function
public Plotter G;
// Internal class for realization of graph function

class Plotter{
    // rane of the coordinats
    private double Xmin=0, Xmax=10.0, Ymin=0, Ymах= 120.0;
    // graph line color:
    private Color clr;
    // grid line color:
    private Color gclr;
    // class constructor
    Plotter(){
// read the text field and convert it into the number:
       /* try{
            Xmax=Double.valueOf(xmaxTF.getText());}
        catch(NumberFormatException е){
            xmaxTF.setText("10");
            Xmax=10;}*/
// initializing grid line color:
        gclr=Color.GRAY;
// initializing graph line color:
        clr=Color.BLACK;
    }
    // the function that is being displayed:
    private double f(double x){
        return (3*Math.exp(0.4*x)); }
    // methode for the grid display
    public void plot(Graphics Fig){
// parameters for the range in which graph is being displayed
        int H,W,h,w,s=20;
        H=getHeight();
        W=getWidth();
        h=H-2*s;
        w=W-2*s;
// clearing the graph
        Fig.clearRect(0,0,W,H);
// index and quantity of grid lines
        int k, nums=10;
        Fig.setColor(Color.BLACK);
// coordinate axis:
        Fig.drawLine(s,s,s,h+s);
        Fig.drawLine(s,s+h,s+w,s+h);
        for(k=0;k<=nums;k++){
            Fig.drawLine(s+k*w/nums, s+h, s+k*w/nums, s+h+5);
            Fig.drawLine(s-5,s+k*h/nums,s,s+k*h/nums);
            Fig.drawString(Double.toString(Xmin+k*(Xmax-Xmin)/nums),
                    s+k*w/nums-5,s+h+15);
            Fig.drawString(Double.toString(Ymin+k*(Ymах-Ymin)/nums),s-17,
                    s+h-1-k*h/nums);
        }
        Fig.setColor(gclr);
// grid lines:
            for(k=1;k<=nums;k++){
                Fig.drawLine(s+k*w/nums,s,s+k*w/nums,h+s);
                Fig.drawLine(s,s+(k-1)*h/nums,s+w,s+(k-1)*h/nums);
            }
// grаph display:
        Fig.setColor(clr);   // setting graph line color
// scaling coefficient:
        double dx=(Xmax-Xmin)/w,dу=(Ymах-Ymin)/h;
        // cartesian coordinates:
        double x1,x2,y1,y2;
// window coordinates:
        int h1,h2,w1,w2;
// initial values
        x1=Xmin;
        y1=0;
        w1=s;
        h1=h+s-(int)Math.round(y1/dу);
        int step=5;
// displaying the dots and connecting them with lines:
        for(int i=step;i<=w;i+=step){
            x2=i*dx;
            y2=y1+(x2-x1)*f(x2) ;
            w2=s+(int)Math.round(x2/dx);
            h2=h+s-(int)Math.round(y2/dу);
            Fig.drawLine(w1,h1,w2,h2);
            Fig.drawRect(w1-2,h1-2,4,4);
// new values:
            x1=x2;
            y1=y2;
            w1=w2;
            h1=h2;
        }
    }
}
// panel constructor
PPanel(){
// creating the object for the plot function:
    G=new Plotter();
    // setting the background color of the panel:
    setBackground(Color.WHITE);
}
// redefinition of the paint method:
public void paint(Graphics g){
// when redrawing the panel redraw graph as well
    G.plot(g);
}
}
这就是它在调色板上的外观。但当我把它拖到表格上时,什么也没发生。默认元素工作正常。怎么了?

a我把它修好了。 解决方案: 将字节码和编译器版本设置为同一版本。 调整大小问题的解决方案-设置要填充的水平和垂直对齐。
还必须在createUIComponents中创建该类的和对象

当然,对不起,我的错。注释现在被翻译我通过使Plotter类独立并通过ActionListener在常规JPanel上使用它解决了问题我按下按钮,Plotter在JPanel上绘制,但我仍然需要以某种方式覆盖paint方法,因此,每次我调整窗口大小时,图形都会重新绘制。我发现了类似的问题:我将字节码版本设置为1.6,编译器也设置为1.6,现在它添加了正确的代码。很好,仍然无法正常工作,拒绝绘制任何内容,但它增加了至少如果我在明天之前修复它,我将关闭问题最后一个问题,它不会调整大小。我已经设置了可以收缩、可以增长、想要增长,但它仍然非常小,除非我强制将首选大小设置为一些常量。当它是-1,-1-它保持在零度,我猜,大小