Skip to main content

Hello World example

2 replies [Last post]
jantaubert
Offline
Joined: 2007-12-12

I tried the following code:

import javax.swing.JFrame;

import com.sun.scenario.scenegraph.JSGPanel;
import com.sun.scenario.scenegraph.SGGroup;
import com.sun.scenario.scenegraph.SGText;

public class Demo {

public static void main(String[] args) {

JFrame f = new JFrame("Demo");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

JSGPanel panel = new JSGPanel();
SGGroup rootNode = new SGGroup();
panel.setScene(rootNode);

SGText textNode = new SGText();
textNode.setText("Hello World");
rootNode.add(textNode);

f.add(panel);
f.setSize(300, 200);
f.setVisible(true);
}

}

But the text is not displayed in the JFrame. I m using Scenario-0.4.jar on the classpath and JDK6. Do I have to add more to my classpath?

Thanks,
Jan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joshua Marinacci

You need to set the font and location of the text. Keep in mind that
the text node will drawn on the baseline. This means that if you set
the location to (0,0) then your text will be above the top of the
screen.

This code should work:

JFrame f = new JFrame("Demo");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

JSGPanel panel = new JSGPanel();
SGGroup rootNode = new SGGroup();
panel.setScene(rootNode);

SGText textNode = new SGText();
textNode.setText("Hello World");
textNode.setLocation(new Point(50,50));
//textNode.setDrawPaint(Color.BLACK);
//textNode.setFillPaint(Color.BLACK);
textNode.setFont(new Font("Sanserif",Font.PLAIN,12));
rootNode.add(textNode);

f.add(panel);
//f.pack();
f.setSize(300, 200);
f.setVisible(true);

- Josh

On Dec 12, 2007, at 9:53 AM, scenario@javadesktop.org wrote:

> JFrame f = new JFrame("Demo");
> f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
>
> JSGPanel panel = new JSGPanel();
> SGGroup rootNode = new SGGroup();
> panel.setScene(rootNode);
>
> SGText textNode = new SGText();
> textNode.setText("Hello World");
> rootNode.add(textNode);
>
> f.add(panel);
> f.setSize(300, 200);
> f.setVisible(true);

[att1.html]

jantaubert
Offline
Joined: 2007-12-12

Yes, it is working now.
Thanks!