Недавно я изучаю глюонную мобильность и обнаружил, что javafx css функционирует в проводном режиме.
Следуя инструкции " Comments ", я сделал представление под названием "CommentsView", когдаЯ попытался изменить размер шрифта основного текста и дополнительного текста в плитке списка комментариев, это не дало никакого эффекта.
Можете ли вы объяснить, почему -fx-font-size
для текстов в списке не функционировал должным образом?Большое спасибо.
Это мой код:
// CommentsPresenter.java
import com.freedom.demo.Comments;
import com.freedom.demo.model.Comment;
import com.gluonhq.charm.glisten.application.MobileApplication;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.control.FloatingActionButton;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import com.gluonhq.charm.glisten.visual.Swatch;
import com.google.common.base.Joiner;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class CommentsPresenter {
private static final Logger logger = Logger.getLogger(CommentsPresenter.class.getName());
@FXML
private View comments;
@FXML
private ListView commentView;
public void initialize() {
comments.showingProperty().addListener((obs, oldValue, newValue) -> {
if (newValue) {
AppBar appBar = MobileApplication.getInstance().getAppBar();
appBar.setNavIcon(MaterialDesignIcon.MENU.button(e ->
MobileApplication.getInstance().getDrawer().open()));
appBar.setTitleText("Comments");
Swatch.ORANGE.assignTo(comments.getScene());
}
});
final FloatingActionButton floatingActionButton = new FloatingActionButton(MaterialDesignIcon.ADD.text,
e -> MobileApplication.getInstance().switchView(Comments.EDITION_VIEW));
floatingActionButton.showOn(comments);
commentView.setCellFactory(p -> new CommentListCell());
commentView.setPlaceholder(new Label("There are no comments"));
commentView.getItems().add(new Comment("wtx", "hello world!中国"));
}
@FXML
void buttonClick() {
}
}
// CommentListCell.java
import com.freedom.demo.model.Comment;
import com.gluonhq.charm.glisten.control.ListTile;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.layout.VBox;
import java.util.logging.Level;
import java.util.logging.Logger;
public class CommentListCell extends ListCell<Comment>{
private final static Logger logger = Logger.getLogger(CommentListCell.class.getName());
private final ListTile tile = new ListTile();
private Comment comment;
{
tile.getStyleClass().add("comment-list");
}
{
final Button button = MaterialDesignIcon.DELETE.button();
tile.setSecondaryGraphic(new VBox(button));
}
@Override
protected void updateItem(Comment item, boolean empty) {
super.updateItem(item, empty);
comment = item;
if (!empty && item != null) {
tile.textProperty().setAll(item.getAuthor(), item.getContent(), item.getDateStr());
setGraphic(tile);
} else {
setGraphic(null);
}
}
}
и это мой CSS и HTML:
.view {
}
.comment-list {
-fx-background-color: -primary-swatch-50;
-fx-text-fill: -primary-swatch-700;
-fx-padding: 0 0 10 0;
}
.comment-list .primary-text {
-fx-font-size: 30;
-fx-padding: 10 0 10 0;
-fx-text-fill: -primary-swatch-900;
-fx-background-color: green;
}
.comment-list .secondary-text{
-fx-font-size: 20;
-fx-background-color: red;
}
.button.icon-toggle {
-fx-text-fill: -primary-swatch-900;
}
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.mvc.View?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.BorderPane?>
<View fx:id="comments" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="350.0" stylesheets="@comments.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.freedom.demo.views.CommentsPresenter">
<center>
<ListView fx:id="commentView" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
</center>
</View>
После обеда iphone5S симулятор, вид показывался как текущий:
ps: это мое дерево зависимостей:
+--- com.gluonhq:charm:5.0.0
| +--- com.gluonhq:connect:1.4.4
| | \--- org.glassfish:javax.json:1.0.4
| +--- com.gluonhq:charm-cloudlink-client:4.4.7
| | +--- com.gluonhq:connect:1.4.4 (*)
| | +--- com.gluonhq:charm-down-plugin-device:3.6.0
| | | \--- com.gluonhq:charm-down-core:3.6.0 -> 3.8.0
| | +--- com.gluonhq:charm-down-plugin-in-app-billing:3.6.0
| | | \--- com.gluonhq:charm-down-core:3.6.0 -> 3.8.0
| | +--- com.gluonhq:charm-down-plugin-push-notifications:3.6.0
| | | +--- com.gluonhq:charm-down-core:3.6.0 -> 3.8.0
| | | \--- com.gluonhq:charm-down-plugin-runtime-args:3.6.0
| | | \--- com.gluonhq:charm-down-core:3.6.0 -> 3.8.0
| | \--- com.gluonhq:charm-down-plugin-storage:3.6.0 -> 3.8.0
| | \--- com.gluonhq:charm-down-core:3.8.0
| +--- com.gluonhq:charm-glisten-connect-view:5.0.0
| | +--- com.gluonhq:charm-cloudlink-client:4.4.7 (*)
| | \--- com.gluonhq:charm-glisten:5.0.0
| | +--- com.gluonhq:charm-down-plugin-display:3.8.0
| | | \--- com.gluonhq:charm-down-core:3.8.0
| | +--- com.gluonhq:charm-down-plugin-lifecycle:3.8.0
| | | \--- com.gluonhq:charm-down-core:3.8.0
| | +--- com.gluonhq:charm-down-plugin-statusbar:3.8.0
| | | \--- com.gluonhq:charm-down-core:3.8.0
| | \--- com.gluonhq:charm-down-plugin-storage:3.8.0 (*)
| \--- com.gluonhq:charm-glisten:5.0.0 (*)
+--- com.google.guava:guava:26.0 FAILED
+--- com.gluonhq:charm-down-plugin-display:3.8.0 (*)
+--- com.gluonhq:charm-down-plugin-lifecycle:3.8.0 (*)
+--- com.gluonhq:charm-down-plugin-statusbar:3.8.0 (*)
+--- com.gluonhq:charm-down-plugin-storage:3.8.0 (*)
\--- com.gluonhq:robovm-cocoatouch:2.3.1-ios11
\--- com.gluonhq:robovm-objc:2.3.1-ios11