【发布时间】:2015-02-03 11:53:03
【问题描述】:
代码如下:
package je3.thread;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
/**
* Text seemed to be anchored at the bottom left corner.
* See screenshot here: http://i60.tinypic.com/2mnnmrn.jpg
*/
public class ShowText extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Pane pane = new Pane();
pane.setPadding(new Insets(0, 0, 0, 0));
Text text1 = new Text(20, 20, "Programming fun");
// text1.setFont(Font.font("Courier", BOLD, FontPosture.ITALIC, 15));
Text text2 = new Text(30, 30, "Programming fun");
Text text3 = new Text(40, 40, "Programming fun");
// text3.setFill(Color.RED);
// text3.setUnderline(true);
pane.getChildren().addAll(text1, text2,text3);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
}
}
结果:
我正在寻找一种指定坐标并将给定文本对象的中心定位到该坐标的方法。
【问题讨论】:
-
不是重复的。将文本置于区域中心与将文本置于某个坐标并将文本中心锚定到该坐标是完全不同的。
-
嗯,有两件事:您的问题缺少一些描述性文字来说明您打算问什么。其次:链接的可能重复项为您提供了关于如何在 JavaFX 中居中文本的明确提示。有了这些知识,就很容易为您的问题编写解决方案..
-
好的,我添加了一些关于我的目标的描述性文本。通过查看您发布的链接,我看不到一个简单的解决方案。如果这对您来说很明显,为什么不写下答案呢? ;-)
标签: java user-interface javafx