Yes, I am mixing awt and swing components, but maybe there is an easy fix because I dont know Java all that well.
My canvas object overrides paint and update:
package demo;
import java.awt.*;
public class rectangle extends Canvas {
public rectangle() {
this.setSize(500,300);
this.setVisible(true);
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.YELLOW);
g2.fill3DRect(0, 0, 500, 300, true);
}
public void update(Graphics g) { paint(g); }
}
When my JComboBox opens over top of this it doesnt paint on top of it. As an example, here is a JFrame that demonstrates what i'm talking about:
package demo;
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class ASframe extends JFrame {
public ASframe() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
ArrayList listNames = new ArrayList();
listNames.add("One");
listNames.add("Two");
listNames.add("Three");
listNames.add("Four");
rectangle r = new rectangle();
JComboBox listBox = new JComboBox(listNames.toArray());
listBox.setVisible(true);
JPanel listPane = new JPanel();
listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
listPane.add(listBox);
listPane.add(r);
this.setResizable(false);
this.add(listPane);
this.pack();
}
public static void main(String arg[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ASframe().setVisible(true);
}
});
}
}
Whats really interesting is that if the rectangle is smaller then the JComboBox, no issues at all. So, change the rectangle to 300x20 and it works as expected.
Thanks in advance.