Hi- this is working (kind of ) , but its instantly refreshing over the boxes Im trying to draw. I can only see the boxes briefly when resizing the window. So its like they are drawn and then instantly drawn over. I've been pulling out small chunks of hair all morning over it...!!! Please someone save me !
Heres some code, its part of a big program I'm writing, so I've tried to cut out lots of the irrelevant stuff.
import java.awt.*; import javax.swing.JComponent; import javax.swing.JPanel; public class Artything extends JPanel { private static final long serialVersionUID = 7747161700374293379L; public Artything(Graphics g) { g2d = (Graphics2D) g; } Graphics2D g2d; public void paintComponent(Graphics g) { super.paintComponent(g); for (int i=10; i<300; i++){ g2d.fillRect(10+i, 10+i, 100, 150); } } }
Here is the class I'm trying to use it inside...or a small part of it
public class NewJFrame extends javax.swing.JFrame { .... public JPanel labelLayoutJPanel; .... pack(); ArtyThing renderer = new ArtyThing labelLayoutJPanel.getGraphics()); labelLayoutJPanel.add(renderer); .... }
Any help appreciated. Thanks
PS Its all running from here:
import java.util.Vector; import javax.swing.SwingUtilities; public class RunClient { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { DatabaseManager dbm = new DatabaseManager(); Vector<String> list = dbm.returnList(); NewJFrame inst = new NewJFrame(); inst.initGUI(list); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); } }
Tell me its not a threading problem please Anyone who helps is welcome to free guitar advice =P