2017-09-13 104 views
0

我试图使一行文本由一个名称和一个文本字符串组成。我想要这个名字是一个超链接,剩下的只是纯文本。在JavaFX中禁用TextFlow中的项目之间的间距

我认为TextFlow会很好,但问题是它会自动在超链接和文本之间放置一个空格。如果我想TextFlow的是例如

Jane的真棒

的TextFlow将一个

Jane的真棒

有一个方法或CSS属性来禁用此行为?

回答

2

解决方案

您可以通过CSS样式移除填充:

.hyperlink { 
    -fx-padding: 0; 
} 

或者,如果你愿意,你可以做到这一点的代码:

link.setPadding(new Insets(0)); 

背景

默认设置可以在modena.css文件中jfxrt.jar文件与JRE分发包装中找到,它是:

-fx-padding: 0.166667em 0.25em 0.166667em 0.25em; /* 2 3 2 3 */ 

示例应用程序

sample application

在样本截图第二超链接有焦点(因此它的虚线边框)。

import javafx.application.Application; 
import javafx.geometry.Insets; 
import javafx.scene.Scene; 
import javafx.scene.control.Hyperlink; 
import javafx.scene.layout.Pane; 
import javafx.scene.text.Text; 
import javafx.scene.text.TextFlow; 
import javafx.stage.Stage; 

public class HyperSpace extends Application { 

    @Override 
    public void start(Stage stage) { 
     TextFlow textFlow = new TextFlow(
      unstyle(new Hyperlink("Jane")), 
      new Text("'s awesome "), 
      unstyle(new Hyperlink("links")) 
     ); 
     stage.setScene(new Scene(new Pane(textFlow))); 
     stage.show(); 
    } 

    private Hyperlink unstyle(Hyperlink link) { 
     link.setPadding(new Insets(0)); 
     return link; 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 
相关问题