我需要一个带有副标题的标签,就像在这里一样 sample image
首先要考虑的是扩展GridPane并创建一个新的自定义窗格,如:
package Components.CustomLabel;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
/**
*
* @author Aamir khan
*/
public class LabelWithSubTitle extends GridPane {
private final Label title = new Label();
private final Label subTitle = new Label();
private final ImageView thumb = new ImageView();
public LabelWithSubTitle(String titleString, String subString, Image thumb) {
setTitle(titleString);
setSubTitle(subString);
setThumb(thumb);
init();
}
private void setSubTitle(String sub) {
subTitle.setText(sub);
}
private void setThumb(Image img) {
thumb.setImage(img);
}
private void setTitle(String titleString) {
title.setText(titleString);
}
private void init() {
add(thumb, 0, 0, 1, 2);
add(title, 1, 0);
add(subTitle, 1, 1);
}
}
我对此完全陌生,所以任何想法我怎么能实现这个目标?