Java SVG not displaying correctly

Ok, I have a Java program that displays some fragments that are SVG in FlowLayout. It does this by being a ScrabbleRack class and extending a JPanel, and then adding JSVGCanvas fragments to this panel.

Subsequently, I created a frame and added a panel. (packed it and displayed). When the panel appears, it is displayed incorrectly. It simply displays the first fragment, and then in the space where the remaining fragments should be displayed, there is whitearea.

But if I change the frame size to any amount, the image will be displayed 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 properly display this panel for the first time.

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


batik SVG Java , .

+3
3

, EDT.

:

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            MyWindow window = new MyWindow();
            MyWindow.setVisible(true);
            }
        });
    }

MyWindow.

http://leepoint.net/JavaBasics/gui/gui-commentary/guicom-main-thread.html ( )

+1

Batik 35922, : https://issues.apache.org/bugzilla/show_bug.cgi?id=35922

, , JSVGCanvas ( ScrabbleRackGUI) (), URI JSVGCanvas.

0

, :   ScrabbleRackGUI rack = ScrabbleRackGUI (1); , int.

-, FlowLayout JPanel, JPanel FlowLayout . super(); JPanel.

Event Dispatching Thread (EDT), .  SwingUtilities.invokeLater( Runnable() { // }

URI : setURI (.. f.toURI() toURL() ToString()); f.toURL() .

Hope this helps.

0
source

Source: https://habr.com/ru/post/1744120/


All Articles