Skip to main content

Clipping text within translated group - not working as expected?

2 replies [Last post]
Joined: 2004-12-20

I'm seeing a strange problem with some code that uses clipping.

If I set clipping on a vanilla Text object then everything works as expected. However, if I then put that Text object into a translated group then the Text disappears - it's as if the clip region is not being translated. Here is some example code:

import javafx.scene.geometry.Line;<br />
import javafx.scene.paint.Color;<br />
import javafx.application.Frame;<br />
import javafx.application.Stage;<br />
import javafx.scene.text.*;<br />
import javafx.scene.*;<br />
import javafx.scene.geometry.*;<br />
import javafx.scene.transform.*;</p>
<p>public class Test {</p>
<p>Frame {<br />
    title: "MyApplication"<br />
    width: 200<br />
    height: 300</p>
<p>    closeAction: function() {<br />
        java.lang.System.exit( 0 );<br />
<p>    var t:Translate,</p>
<p>    stage: Stage {<br />
        content: [<br />
            Group {<br />
                transform: t = Translate { x: 18, y: 40 }<br />
                content: [<br />
                    Group {<br />
                        content: [<br />
                            Text {<br />
                                // THIS CAUSES THE TEXT TO DISAPPEAR<br />
                                clip: Rectangle { x: 0, y: 0, width: 150, height: 30 }<br />
                                font: Font {<br />
                                    name: "Sans Serif"<br />
                                    size: 41<br />
                                    style: FontStyle.BOLD<br />
                                }<br />
                                content: "SOME VALUE TEXT"<br />
                                stroke: Color.BLACK<br />
                                smooth: false<br />
                            },<br />
                        ]<br />
                    }<br />
                ]<br />
            }<br />
        ]<br />
<p>    visible: true<br />

As a work around I can amend the clip calculation as follows, which seems to work:

clip: Rectangle { x: -1 * t.x, y: -1 * t.y, width: 150 + t.x, height: 30 + t.y }

Am I using clip incorrectly or is this a bug in the API? I'm using the JavaFX Preview SDK installed via the Netbeans plugin.



Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-03-27

I don't know if this will help you, but i just played a bit with clipping:

package cliptest;

import javafx.scene.*;
import javafx.scene.geometry.*;
import javafx.scene.paint.Color;
import javafx.application.*;
import java.lang.System;
import javafx.scene.transform.*;

public class GeClipped extends CustomNode {
public attribute height:Integer = 100;
public attribute width:Integer = 50;
private attribute festeBreite:Integer = 50;
private attribute festeHoehe:Integer = 100;

public function create():Node{
content: bind[
transform: Translate.translate(5,5)
Rectangle {
width: bind width, height: bind height
does not work (Rectangle disappears):
width: bind 100, height: bind 100
width: 100, height: 100
width: bind festeBreite, height: 100
width: bind festeBreite, height: bind festeHoehe

width: bind height, height: 100
width: bind festeBreite, height: bind height
fill: Color.BLACK
Rectangle {
width: bind width - 50
height: bind height - 50

var frame:Frame = Frame {
var stageRef:Stage;
title: "ClippingTest"
width: 200
height: 200
closeAction: function() {
java.lang.System.exit( 0 );
visible: true

stageRef = Stage {
content: [
height: bind stageRef.height
width: bind stageRef.width


seems at least one node attribute must be bind to a same attribute clipping uses

Joined: 2004-12-20

Thanks for this, using binding is definitely a better workaround.

I still think that *all* elements of a group (i.e. clipping) should also be translated. Maybe someone from the JFX team could comment?



PS - Sorry it took so long for me to reply!