Good evening everyone;
I have JSVGCanvas (component from batik framework) on i am displaying an svg
document on canvas with links. I would like to open a new window(jframe) on
my swing when a link clicked. therefore i am using a linkActivated event.
However, my problem is
private JPanel contentPane;
File f;
JSVGCanvas svgCanvas;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
trialgui frame = new trialgui();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public trialgui() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 452, 418);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
f = new File("./links.svg");
svgCanvas = new JSVGCanvas();
if(f.exists()==true){System.out.println("file is ok");}
try {
svgCanvas.setURI(f.toURL().toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
contentPane.add(svgCanvas, BorderLayout.CENTER);
svgCanvas.setMySize(new Dimension(100,100));
JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
svgCanvas.setURI(f.toURL().toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
contentPane.add(btnNewButton, BorderLayout.NORTH);
svgCanvas.addLinkActivationListener(new LinkActivationListener() {
@Override
public void linkActivated(LinkActivationEvent arg0) {
System.out.println("here is working");
try {
JFrame gh = new JFrame();
gh.setVisible(true);
f = new File("./links.svg");
svgCanvas.setURI(f.toURL().toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("here");
}
});
}
when user clicks on a link svgcanvas displays the link within same canvas.So
in order to prevent this i set initial svg
svgCanvas.setURI(f.toURL().toString()); when link activated triggered.
However, referenced link appears in same canvas because of method is not
working. If i put the same method in a button event when i click to button
it bring backs the initial svg to my svgcanvas.
Could anyone tell me why this event acts different than button event and how
can i possibly solve this problem ?
Regards ....
--
View this message in context:
http://batik.2283329.n4.nabble.com/JSVGCanvas-link-activated-event-behavior-difference-tp4655476.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]