I have an issue with styling my TableView, because when I open new window with TableView it has something like on the picture below:
I don't know what causes it. When I click on another row in the table it's gone:
I also attach my CSS for table-view below:
.table-view{
-fx-background-color: -fx-color-navyBlue;
}
.table-view .filler{
-fx-background-color: -fx-color-navyBlue;
}
.table-view:focused{
-fx-background-color: -fx-color-navyBlue;
}
.table-view .column-header-background{
-fx-background-color: -fx-color-navyBlue;
-fx-border-color: -fx-color-navyBlue;
}
.table-view .column-header-background .label{
-fx-background-color: -fx-color-darkGray;
-fx-text-fill: -fx-color-orange;
}
.table-view .column-header {
-fx-background-color: -fx-color-darkGray;
-fx-border-width: 2;
-fx-border-color: -fx-color-navyBlue;
}
.table-view .table-cell{
-fx-text-fill: -fx-color-lightGray;
-fx-alignment: center;
-fx-border-width: 2;
-fx-border-color: -fx-color-navyBlue;
}
.table-view .table-row-cell{
-fx-background-color: -fx-color-navyBlue, -fx-color-darkGray;
-fx-table-cell-border-color: -fx-color-navyBlue;
}
.table-view .table-row-cell:selected * {
-fx-background-color: -fx-color-orange;
-fx-text-fill: -fx-color-navyBlue;
}
Also my TableView Column Resize Policy is constrained-resize and maybe it causes it? But when it's unconstrained-resize it looks worse because of additional "empty" column like below:
Any tip how to get rid of it on window load?
I did what I could to get make this runnable so css doesnt look good because I was using the one from the question but had to make some edits to get it to work. If you uncomment the one line it gets rid of the third column I know you said you set it to resize I cannot replicate the issue your having if you take this modify it so you get the issue and post it I may be able to help otherwise probably not I would check where you set the table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); and make sure its executing correctly if you do it in fxml try setting it on initialization as well and see if that fixes the problem
public class Main extends Application {
public static void main(String[] args) { launch(args); }
#Override
public void start(Stage stage) {
ObservableList<Person> data = FXCollections.observableArrayList(new Person("First", "Last"));
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setMinWidth(100);
firstNameCol.setCellValueFactory(new PropertyValueFactory<>("firstName"));
TableColumn lastNameCol = new TableColumn("Last Name");
lastNameCol.setMinWidth(100);
lastNameCol.setCellValueFactory(new PropertyValueFactory<>("lastName"));
TableView<Person> table = new TableView<>();
table.setItems(data);
table.getColumns().addAll(firstNameCol, lastNameCol);
//table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
Button addButton = new Button("Add");
addButton.setOnAction(event -> data.add(new Person("First","Last")));
VBox vbox = new VBox();
vbox.getChildren().addAll(table, addButton);
Scene scene = new Scene(new Group(vbox));
scene.getStylesheets().add(String.valueOf(getClass().getClassLoader().getResource("tableview.css")));
stage.setScene(scene);
stage.show();
}
public static class Person {
private final SimpleStringProperty firstName;
private final SimpleStringProperty lastName;
private Person(String fName, String lName) {
this.firstName = new SimpleStringProperty(fName);
this.lastName = new SimpleStringProperty(lName);
}
public String getFirstName() { return firstName.get(); }
public void setFirstName(String fName) { firstName.set(fName); }
public String getLastName() { return lastName.get(); }
public void setLastName(String fName) { lastName.set(fName); }
}
}
tableview.css
.table-view{
-fx-background-color: navy;
}
.table-view .filler{
-fx-background-color: navy;
}
.table-view:focused{
-fx-background-color: navy;
}
.table-view .column-header-background{
-fx-background-color: navy;
-fx-border-color: navy;
}
.table-view .column-header-background .label{
-fx-background-color: darkGray;
-fx-text-fill: orange;
}
.table-view .column-header {
-fx-background-color: darkGray;
-fx-border-width: 2;
-fx-border-color: navy;
}
.table-view .table-cell {
-fx-text-fill: lightGray;
-fx-alignment: center;
-fx-border-width: 2;
-fx-border-color: navy;
}
.table-view .table-row-cell{
-fx-background-color: navy, darkGray;
-fx-table-cell-border-color: navy;
}
.table-view .table-row-cell:selected * {
-fx-background-color: orange;
-fx-text-fill: navy;
}
Related
I need an advice with the styling of date picker module in Java FX with an assistance of CSS classes.
It is specifically the popup window in which I used also the scenic view to look up the CSS code. But doesn't work in the popup window. I need a help how to style popup in the calendar view.
(using intelijIdea)
This is my code and the attached picture.
.date-picker .combo-box {
-fx-background-insets:0px ;
-fx-border-width: 0px;
}
.date-picker .text-field{
-fx-background-radius:0px ;
-fx-border-color: transparent;
}
.date-picker .arrow-button{
-fx-background-radius:0px ;
-fx-background-color: #232323;
}
.date-picker .arrow-button .arrow{
-fx-background-radius:0px ;
-fx-background-color: #1783CC;
}
.date-picker .arrow-button:hover .arrow{
-fx-background-radius:0px ;
-fx-background-color: #40a9ef;
}
.date-picker .button {
-fx-background-color: transparent;
-fx-border-color:transparent;
-fx-pref-height: 35px;
-fx-pref-width: 35px;
}
.date-picker .button:hover {
-fx-border-color:transparent;
-fx-pref-height: 35px;
-fx-pref-width: 35px;
}
.date-picker .button .arrow:pressed {
-fx-border-color:transparent;
-fx-pref-height: 35px;
-fx-pref-width: 35px;
}
.date-picker .cell {
-fx-background-color: #232323;
-fx-pref-width:20px ;
-fx-pref-height:25px ;
}
.date-picker .cell:hover {
-fx-background-color: #1783CC;
-fx-pref-width:20px ;
-fx-pref-height:25px ;
}
.date-picker .cell:focused {
-fx-background-color:#11659e;
-fx-pref-width:20px ;
-fx-pref-height:25px ;
}
.date-picker-popup {
-fx-border-color: #1783CC;
-fx-background-color: black;
}
Most style classes of the DatePicker popup can be found in the DatePickerContent.java or in one of the JavaFX's theme stylesheet.
For instance, if you're using the modena theme then you will find the these styleclasses in modena.css (from line 2934)
A quick workaround when using ScenicView would be to prevent the popup from being closed:
datePicker.setOnHidden(new EventHandler<Event>() {
#Override
public void handle(Event event) {
datePicker.show();
}
});
this is the interface of a chat app using javaFX. The chat window is a ListView component and I'm using CSS to polish it a little bit. Here are the CSS and the screenshot:
.list-cell {
display: inline-block;
-fx-min-width: 50px;
-fx-background-color: lightyellow;
-fx-background-radius: 30px;
-fx-border-radius: 20px;
-fx-border-width: 2px;
-fx-border-style: solid;
-fx-border-color: #666666;
}
.list-cell:empty {
-fx-background-color: transparent;
-fx-border-width: 0px;
}
The problem is that I want to change the width of each listCell depending on the length of text. I've tried to set minWidth prefWidth (for example 50px) in the CSS file or using listView.setCellFactory but nothing happens. The length does not change at all. I wonder that can I change the length of each cell in a listView like that or not (or in order to do that I must use something like an HBox/VBox/seperator...)
Use a cell factory that sets the graphic to a Label, and style the label. E.g.:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.stage.Stage;
public class FormattedListCell extends Application {
#Override
public void start(Stage primaryStage) {
ListView<String> listView = new ListView<>();
listView.getItems().addAll("One", "Two", "Three", "Four");
listView.setCellFactory(lv -> new ListCell<String>() {
private final Label label = new Label();
#Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
} else {
label.setText(item);
setGraphic(label);
}
}
});
Scene scene = new Scene(listView, 400, 400);
scene.getStylesheets().add("formatted-list-cell.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
and modify the stylesheet:
.list-cell .label {
display: inline-block;
-fx-min-width: 50px;
-fx-background-color: lightyellow;
-fx-background-radius: 30px;
-fx-border-radius: 20px;
-fx-border-width: 2px;
-fx-border-style: solid;
-fx-border-color: #666666;
}
.list-cell:empty .label {
-fx-background-color: transparent;
-fx-border-width: 0px;
}
You may need to actually style the list cell (as well as the label inside it) to get the exact style you want, but this should get you started.
Here is a more complete CSS file, which uses -fx-background so that the text color will automatically adjust, manages the selection color, and also adds some styles to the list cell itself:
.list-cell {
-fx-background-color: transparent ;
-fx-padding: 0 ;
}
.list-cell .label {
display: inline-block;
-fx-background: lightyellow;
-fx-background-color: -fx-background ;
-fx-background-radius: 30px;
-fx-border-radius: 20px;
-fx-border-width: 2px;
-fx-border-style: solid;
-fx-border-color: #666666;
-fx-padding: 12px ;
}
.list-cell:empty .label {
-fx-background-color: transparent;
-fx-border-width: 0px;
}
.list-cell:selected .label {
-fx-background: -fx-selection-bar ;
}
I have got this code:
private void createAndAddCommonInformationSection(){
Text text = new Text("CommonText");
gridPane.add(header);
}
The should appear in white color, so I have a CCS-file as follows:
.root {
-fx-base: rgb(50, 50, 50);
-fx-background: rgb(50, 50, 50);
-fx-control-inner-background: rgb(50, 50, 50);
}
.tab {
-fx-background-color: linear-gradient(to top, -fx-base, derive(-fx-base,30%));
}
.menu-bar {
-fx-background-color: linear-gradient(to bottom, -fx-base, derive(-fx-base,30%));
}
.tool-bar:horizontal {
-fx-background-color:
linear-gradient(to bottom, derive(-fx-base,+50%), derive(-fx-base,-40%), derive(-fx-base,-20%));
}
.button {
-fx-background-color: transparent;
}
.button:hover {
-fx-background-color: -fx-shadow-highlight-color, -fx-outer-border, -fx-inner-border, -fx-body-color;
-fx-color: -fx-hover-base;
}
.table-view {
-fx-table-cell-border-color:derive(-fx-base,+10%);
-fx-table-header-border-color:derive(-fx-base,+20%);
}
.split-pane:horizontal > * > .split-pane-divider {
-fx-border-color: transparent -fx-base transparent -fx-base;
-fx-background-color: transparent, derive(-fx-base,20%);
-fx-background-insets: 0, 0 1 0 1;
}
.my-gridpane {
-fx-background-color: radial-gradient(radius 100%, derive(-fx-base,20%), derive(-fx-base,-20%));
}
.separator-label {
-fx-text-fill: orange;
}
.text{
-fx-text-fill: white;
}
Everythin is working fine with the CSS-file, except the the color of the text in my code snippet does not appear in the expected color.
I have already tried
-fx-fill: white;
and
-fx-fill-text: white;
but nothing helps.
What am I doing wrong?
According to the documentation, Text nodes have no default style class. so you need
text.getStyleClass().add("text");
in order for the text node to match the CSS selector. Then
.text {
-fx-fill: white ;
}
will work.
Typically you would use a Label along with the fx-text-fill property if you want to style it with CSS, though adding a style class manually to a Text node should work.
I have .css when the row is selected which is fine.
However when I click off the row it changes the row color grey with a black font, is there any way to edit this css?
.table-view {
-fx-base: transparent;
-fx-control-inner-background: transparent;
-fx-background-color: #507CA6;
-fx-padding: 5;
}
.table-view .column-header-background {
-fx-background-color: transparent;
}
.table-view .column-header, .table-view .filler {
-fx-size: 35;
-fx-border-width: 0 0 1 0;
-fx-background-color: transparent;
-fx-border-color: #B4D9FD;
-fx-border-insets: 0 10 1 0;
}
.table-view .column-header .label {
-fx-font-size: 14pt;
-fx-font-family: "Segoe UI Light";
-fx-text-fill: white;
-fx-alignment: center-left;
-fx-opacity: 1;
}
.table-view:focused .table-row-cell:filled:focused:selected {
-fx-background-color: #273D51;
}
Any help would be appreciated.
Try this:
/* When control is selected but not focused */
.table-row-cell:filled:selected,
.table-row-cell:filled > .table-cell:selected {
-fx-background: red;
}
first make selected class than use this script, i always use this $("tr").click(function(){
$(this).addClass("selected").siblings().removeClass("selected");
});
I try to change the radio-buttons size in my app build with FXML and CSS.
I use the sceneBuilder.
Thanks for your help !
Here is my actual CSS code for the radio-buttons :
.radio-button .radio{
-fx-border-width : 1px ;
-fx-border-color : #000 ;
-fx-background-color : white ;
-fx-background-image : null ;
-fx-border-radius : 15px ;
-fx-height : 15px ; /* Not working */
height : 5px ; /* Not working */
}
.radio-button .radio:selected{
-fx-background-color : white ;
-fx-background-image : null ;
}
.radio-button -radio:armed{
-fx-background-color : white ;
-fx-background-image : null ;
}
.radio-button -radio:determinate{
-fx-background-color : white ;
-fx-background-image : null ;
}
.radio-button -radio:indeterminate{
-fx-background-color : white ;
-fx-background-image : null ;
}
-fx-padding: 10px;
A single padding value means that all padding are the same, if a set of four padding values is specified, they are used for the top, right, bottom, and left edges of the region.
from the JavaFX CSS Reference Guide
Example:
CssTest.java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class CssTest extends Application
{
public void start(Stage stage) throws Exception
{
BorderPane root = new BorderPane();
RadioButton radio = new RadioButton("radio-text");
root.setCenter(radio);
root.getStylesheets().add(getClass().getResource("/radio.css").toExternalForm());
stage.setScene(new Scene(root));
stage.show();
}
public static void main(String[] args)
{
launch(args);
}
}
radio.css
.radio-button .radio {
-fx-border-width: 1px;
-fx-border-color: #000;
-fx-background-color: white;
-fx-background-image: null;
-fx-border-radius: 15px;
-fx-padding: 4px;
}
.radio-button .radio:selected {
-fx-background-color: white;
-fx-background-image: null;
}
.radio-button -radio:armed {
-fx-background-color: white;
-fx-background-image: null;
}
.radio-button -radio:determinate {
-fx-background-color: white;
-fx-background-image: null;
}
.radio-button -radio:indeterminate {
-fx-background-color: white;
-fx-background-image: null;
}
.radio-button .dot {
-fx-background-radius: 15px;
-fx-padding: 8px;
}
result
For more inspirational JavaFX CSS themes, check win7glass.css from GreggSetzer/JavaFX-CSS-Themes