xmlgraphics-batik-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Venkataramana_Jaladurgam <Venkataramana_Jaladur...@Satyam.com>
Subject RE: Mix SVG and Swing components
Date Thu, 10 Feb 2005 14:06:26 GMT
I am trying to insert the Swing components in the painting chain. The swing
component is scaled, but the area is not increased. The text and the cursor
in the swing component become larger, but the area occupied by the swing
component is not increased.

Any suggestions. I am attaching the program too.

See the CustTextField is used to introducte JTextField into the painting
Any help is really appreciated.

package com.jvr.test;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import org.apache.batik.swing.*;
import org.apache.batik.swing.gvt.*;
import org.apache.batik.swing.svg.*;

public class G2DFrame
    class CustTextField extends JTextField {
        public CustTextField(int length) {
        public void paint(Graphics g) {
            Graphics2D g2d = (Graphics2D)g;
	JFrame frame;
	JButton button = new JButton("Load...");
	JLabel label = new JLabel();
	JSVGCanvas svgCanvas = new JSVGCanvas();
	//Swing objects to overlay the svg elements
	//JTextField aTxt = new JTextField(10);
	CustTextField aTxt = new CustTextField(10);
	public G2DFrame(JFrame f) {
		frame = f;
		aTxt.setText("A TextBox");

	public JComponent createComponents() {
		final JPanel panel = new JPanel(new BorderLayout());

		JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT));

		panel.add("North", p);
		//panel.add("Center", testSVGCanvas);
		panel.add("Center", svgCanvas);

		// Set the button action.
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent ae) {
				JFileChooser fc = new JFileChooser(".");
				int choice = fc.showOpenDialog(panel);
				if (choice == JFileChooser.APPROVE_OPTION) {
					File f = fc.getSelectedFile();
					try {
					} catch (IOException ex) {

		// Set the JSVGCanvas listeners.
SVGDocumentLoaderAdapter() {
			public void
documentLoadingStarted(SVGDocumentLoaderEvent e) {
				label.setText("Document Loading...");
				//Add the text field now

			public void
documentLoadingCompleted(SVGDocumentLoaderEvent e) {
				label.setText("Document Loaded.");

GVTTreeBuilderAdapter() {
			public void gvtBuildStarted(GVTTreeBuilderEvent e) {
				label.setText("Build Started...");

			public void gvtBuildCompleted(GVTTreeBuilderEvent e)
				label.setText("Build Done.");

GVTTreeRendererAdapter() {
			public void gvtRenderingPrepare(GVTTreeRendererEvent
e) {
				label.setText("Rendering Started...");

			public void
gvtRenderingCompleted(GVTTreeRendererEvent e) {
				//Sample scaling of the text field
				//Repaint the text field now

		return panel;
	public static void main(String[] args) {
		JFrame f = new JFrame("Batik Extension");
		G2DFrame app = new G2DFrame(f);
		f.setSize(400, 400);


-----Original Message-----
From: Thomas DeWeese
To: batik-dev@xml.apache.org
Sent: 1/27/2005 6:35 PM
Subject: Re: Mix SVG and Swing components

Venkataramana_Jaladurgam wrote:

> Is there any way I can scale the swing components along the lines of
> elements if I choose to add Swing components to JSVGCanvas directly.

    Only if you can insert yourself in the components repaint chain.
So for example if you were to override the paintChildren method from
JComponent you might be able to adjust the graphics object prior
to drawing the children to scale/translate them as desired.

> -----Original Message-----
> From: Tonny Kohar [mailto:tonny@kiyut.com] 
> Sent: Wednesday, January 19, 2005 9:16 PM
> To: 'batik-dev@xml.apache.org'
> Subject: Re: Mix SVG and Swing components
> Hi,
>>  I am required to add Swing components to the SVG canvas. I want to
> the
>>batik extensions.
>> The trouble I am facing is in the actual rendering class:
>>The output I am getting in the JSVGCanvas is a static version of
> JTextField.
>>I cannot enter characters or do anything with it. 
>>Any ideas? I believe if I can access JSVGCanvas or the related class
>>the components are being rendered, then I can directly add my swing
>>component to it. But couldn't get how to get it. Batik developers pls.
> help.
> I do not know how to solve your problem, but as far as I know the
> GVT part is render the SVG stuff into Image that will be painted into
> the JSVGCanvas. The package org.apache.batik.gvt.renderer is where the
> rendering stuff.
> How about extending JSVGCanvas or its parent paintComponent method and
> adding your textField there. Or maybe wrap JSVGCanvas and your
> into custom component and using Java JComponent layer or z-order
> capability.
> Regards
> Tonny Kohar

To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org
This email (including any attachments) is intended for the sole use of the
intended recipient/s and may contain material that is CONFIDENTIAL AND
PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or
distribution or forwarding of any or all of the contents in this message is
STRICTLY PROHIBITED. If you are not the intended recipient, please contact
the sender by email and delete all copies; your cooperation in this regard
is appreciated.

To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org

View raw message