Oi pessoal, bem eu tô com problema na mudança de cor de um JPanel usando o netbeans. Eu sobreescrevo o método paintComponent, mas não surte efeito e o fundo que aparece é o do JFrame. Aí abaixo o código das classes usadas.
[code]public class Main {
public static void main(String[] args) {
frame f=new frame();
f.setSize(300,300);
f.setVisible(true);
}
}[/code]
[code]public class frame extends javax.swing.JFrame {
/** Creates new form frame */
public frame() {
initComponents();
pane p=new pane();
setContentPane(p);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 51, 51));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 583, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 427, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
// Variables declaration - do not modify
// End of variables declaration
}[/code]
[code]import java.awt.*;
public class pane extends javax.swing.JPanel {
/** Creates new form pane */
public pane() {
initComponents();
}
@Override
public void paintComponent(Graphics g){
g.setColor(Color.red);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>
// Variables declaration - do not modify
// End of variables declaration
}[/code]
Valeu desde já galera.