views:

70

answers:

0

Ok, I have a java program, that displays some tiles that are SVGs in a FlowLayout. Does this by being a class ScrabbleRack, and extending JPanel, then adding JSVGCanvas tiles to this panel.

Afterwards I created a frame and added the panel, this.(packed it and displayed it). On appearing, the panel does not display properly. It just displays the first tile and then in the space where the rest of the tiles should be displayed, there is whitearea.

But if i resize the frame by any amount, the image will render correctly.

public class ScrabbleRackGUI extends JPanel{
    ScrabbleRack rack=new ScrabbleRack();
    JSVGCanvas rackContentsImages[]=new JSVGCanvas[8];

public ScrabbleRackGUI() {
   setLayout(new FlowLayout());
   createComponents();
}
public void createComponents() {
    //INITIALISE SOURCE IMAGES
    initImages();
    for (int i=0;i<rackContentsImages.length;i++){
        this.add(rackContentsImages[i]);
    }
}
private void initImages(){
    File tempImages[]=new File[8];
    for(int i=0;i<8;i++){
       tempImages[i]= new File("./src/res/rackBackground.svg");
       rackContentsImages[i]=new JSVGCanvas();
       try {
           rackContentsImages[i].setURI(tempImages[i].toURL().toString());
       } catch (MalformedURLException ex) {
           Logger.getLogger(ScrabbleBoardGUI.class.getName()).log(Level.SEVERE, null, ex);
       }
    }
}
public static void main(String args[])
{
    JFrame frame = new JFrame("ScrabbleTest");
    ScrabbleRackGUI rack= new ScrabbleRackGUI(1);
    frame.add(rack);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setSize(214,70);
    frame.setVisible(true);

}
}

Any ideas on how i can get this panel to display properly, first time.

Or some hack that will resize it at the end of the program.

Many thanks in advance, Eric

btw. I used batik to render the svgs in java. (org.apache.batik.swing.JSVGCanvas) It can be downloaded from: http://xmlgraphics.apache.org/batik/download.cgi for those who want to reproduce this problem.