如何消除JPanel的透明度

时间:2016-03-08 11:23:06

标签: java swing

我有一个主要课程 GMate 。此GMate调用 formDashboard 。按下按钮,,我输入数据。按下此表单 formContPanel 上的“确定”按钮。此表单上附有jPanel。此面板在方法 drawCont 中绘制。从图像中可以看出,面板已绘制,但表格的其余部分完全透明(请参阅附图)。绘制的图形是可以的;它的尺寸小于面板尺寸。我删除了一些methdos的尸体,因为它们不是必需的。

enter image description here

这是代码:

GMate.java

public class GMate {
     static formDashboard formD = new formDashboard();
     public static void main(String[] args) {
         formD.setVisible(true);
         formD.pack();
         formD.setTitle("Graphics Main");
     }
 }

formDashjboard.java

public class formDashboard extends javax.swing.JFrame {
    formCont formC  = new formCont();

    public formDashboard() {
         initComponents();
     }

     @SuppressWarnings("unchecked")
     private void btnContourActionPerformed(java.awt.event.ActionEvent evt)     {                                           
         formC.setVisible(true);
         formC.pack();
         formC.setTitle("Contour Plot");
       }                                          
 }

formCont.java

public class formContour extends javax.swing.JFrame {
      int N = 50;
       double[] x = new double[N], y = new double[N];
       double[][] z = new double[N][N];
       Color[][] zcol = new Color[N][N];
       double[] Mm;
       String sExpr;
double x0, x1, y0, y1, dx, dy;
double sc;
Color[] cols = new Color[256];

public formContour() {
    initComponents();
}

private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {                                      
    // TODO add your handling code here:
    Mm = new double[2];
    sExpr = "x*y";
    x0 = -5;
    x1 = 5;
    y0 = -5;
    y0 = 5;
    makeGradient();
    calculateZ(sExpr, x0, x1, y0, y1);
    z = calculateZ(sExpr, x0, x1, y0, y1);
    Mm = calculateMinMax(z);
    sc = 255.0 / (Mm[1] - Mm[0]);
    zcol = calculateZColor(z);
    formContPanel formCP = new formContPanel(zcol);
    formCP.pack();
    formCP.setLocationRelativeTo(null);  
    formCP.setVisible(true);
    formCP.setTitle("The Contour");

   formCP.drawCont();
}                                     

double[] calculateMinMax(double[][] z){
}

double[][] calculateZ(String sExpr, double x0, double x1, double y0, double y1){
}

Color[][] calculateZColor(double[][] z){}

Color calculateGradient(float p){}

void makeGradient(){}
}    
}

formContPanel.java

 public class formContPanel extends javax.swing.JFrame {
Color[][] colors;
Graphics gr;

public formContourPlotPanel(Color[][] cols) {
    initComponents();
    colors = cols;
    gr = jPanel1.getGraphics();
}

void drawCont(){
    int i, j;
    for(i=0; i<colors[0].length; i++){
        for(j=0; j<colors[0].length; j++){
            gr.setColor(colors[i][j]);
            gr.drawLine(i, j, i, j);
        }
    }

}

0 个答案:

没有答案