Skip to main content

text alignment

5 replies [Last post]
mpymm
Offline
Joined: 2007-12-12
Points: 0

Hi,

I posted about this a while back and thought I'd try with scenario 0.6 but with no luck. Here's my test program - if you run it you'll see a redraw issue (the longer string isn't completely rendered) and a jitter issue (the decimal point and numbers to the right move about). I tried it using a JLabel inside an SGComponent (see the commented out code) and that worked fine, but that seems a bit heavyweight... I'd really like to make some headway on using scenario, should I just stick with JLabel for now?

Thanks
Michael

[pre]
public class MpTest {
public static void main(String[] args) {
JFrame frame = new JFrame("mp test") {
{
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setPreferredSize(new Dimension(640, 480));
setLayout(new BorderLayout());

JSGPanel panel = new JSGPanel();
panel.setDoubleBuffered(true);
add(panel, BorderLayout.CENTER);

final SGGroup top = new SGGroup();

// This doesn't work
final SGText text = new SGText();
text.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
text.setText("000.00");
text.setAntialiasingHint(RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
text.setLocation(new Point2D.Float(150, 50));
text.setVerticalAlignment(SGText.VAlign.BASELINE);
SGAlignment align = new SGAlignment();
align.setChild(text);
align.setHorizontalAlignment(SwingConstants.TRAILING);
top.add(align);

/*
// This does what I want
final JLabel text = new JLabel("000.00", SwingConstants.RIGHT);
text.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
text.setPreferredSize(new Dimension(100, 30));
SGComponent c = new SGComponent();
c.setComponent(text);
SGTransform t = SGTransform.createTranslation(100, 100, c);
top.add(t);
*/

panel.setScene(top);

new Thread() {
boolean a = false;
public void run() {
while (true) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
text.setText(a ? "000.00" : "1099.12");
a = !a;
}
});
try {
Thread.sleep(400);
} catch (InterruptedException e) {
//
}
}
}
}.start();
}
};
frame.pack();
frame.setVisible(true);
}
}
[/pre]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
liquid
Offline
Joined: 2005-06-16
Points: 0

BTW, on a pretty recent svn build, your example runs fine (it's definitely broken on 0.6). Seems like it's fixed now.

mpymm
Offline
Joined: 2007-12-12
Points: 0

Yes, confirmed, it works now for me, thanks everyone. Excellent, now I can start to do some serious coding with this :)

Chris Campbell

Hi Michael,

There have been numerous bug fixes since the 0.6 release. Phil recently
fixed the text bounds/alignment issues you reported a while back. I
just ran your testcase against the latest from svn and it seems to be
working properly now. Please let us know if you see any other issues.

Thanks,
Chris

scenario@javadesktop.org wrote:
> Hi,
>
> I posted about this a while back and thought I'd try with scenario 0.6 but with no luck. Here's my test program - if you run it you'll see a redraw issue (the longer string isn't completely rendered) and a jitter issue (the decimal point and numbers to the right move about). I tried it using a JLabel inside an SGComponent (see the commented out code) and that worked fine, but that seems a bit heavyweight... I'd really like to make some headway on using scenario, should I just stick with JLabel for now?
>
> Thanks
> Michael
>
> [pre]
> public class MpTest {
> public static void main(String[] args) {
> JFrame frame = new JFrame("mp test") {
> {
> setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
> setPreferredSize(new Dimension(640, 480));
> setLayout(new BorderLayout());
>
> JSGPanel panel = new JSGPanel();
> panel.setDoubleBuffered(true);
> add(panel, BorderLayout.CENTER);
>
> final SGGroup top = new SGGroup();
>
> // This doesn't work
> final SGText text = new SGText();
> text.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
> text.setText("000.00");
> text.setAntialiasingHint(RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
> text.setLocation(new Point2D.Float(150, 50));
> text.setVerticalAlignment(SGText.VAlign.BASELINE);
> SGAlignment align = new SGAlignment();
> align.setChild(text);
> align.setHorizontalAlignment(SwingConstants.TRAILING);
> top.add(align);
>
> /*
> // This does what I want
> final JLabel text = new JLabel("000.00", SwingConstants.RIGHT);
> text.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
> text.setPreferredSize(new Dimension(100, 30));
> SGComponent c = new SGComponent();
> c.setComponent(text);
> SGTransform t = SGTransform.createTranslation(100, 100, c);
> top.add(t);
> */
>
> panel.setScene(top);
>
> new Thread() {
> boolean a = false;
> public void run() {
> while (true) {
> SwingUtilities.invokeLater(new Runnable() {
> public void run() {
> text.setText(a ? "000.00" : "1099.12");
> a = !a;
> }
> });
> try {
> Thread.sleep(400);
> } catch (InterruptedException e) {
> //
> }
> }
> }
> }.start();
> }
> };
> frame.pack();
> frame.setVisible(true);
> }
> }
> [/pre]
> [Message sent by forum member 'mpymm' (mpymm)]
>
> http://forums.java.net/jive/thread.jspa?messageID=271575
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@scenegraph.dev.java.net
> For additional commands, e-mail: dev-help@scenegraph.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@scenegraph.dev.java.net
For additional commands, e-mail: dev-help@scenegraph.dev.java.net

mpymm
Offline
Joined: 2007-12-12
Points: 0

Hi Chris,

That sounds great; I'll checkout head and try it again. On the same note, I wonder if it would be possible for you guys to set up a nightly build... I can't access remote svn from the office so this would make staying current a lot easier.

Thanks
Michael

liquid
Offline
Joined: 2005-06-16
Points: 0

A more frequently updated build would actually be a great idea ! Bulding the native bindings is especially hard to set up (and now there's one more with the SSE ...) but we digress...