LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-04-2018, 03:04 PM   #1
turay
LQ Newbie
 
Registered: Sep 2017
Posts: 22

Rep: Reputation: Disabled
JavaFX Css?


why css not working?
Main.java
Code:
package sample;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class Main extends Application
{
    @Override
    public void start(Stage stage)
    {
        Label label = new Label("Welcome to JavaFx");

        Group root = new Group();
        ObservableList list = root.getChildren();
        list.add(label);

        Scene scene = new Scene(root, 500, 300);
        scene.getStylesheets().add("a.css");//not work

        stage.setTitle("JavaFX Label");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String[] args)
    {
        launch(args);
    }
}
a.css
Code:
.root {
    -fx-font-size: 14px;
    -fx-font-family: sans-serif;
    -fx-background-color: #4cfffd;
}
.label {
    -fx-font-size: 22px;
    -fx-font-family: "fantasy";
    -fx-text-fill: #77ff67;
    -fx-opacity: 0.6;
    -fx-background-color: red;
}
 
Old 01-05-2018, 02:44 AM   #2
turay
LQ Newbie
 
Registered: Sep 2017
Posts: 22

Original Poster
Rep: Reputation: Disabled
ok, i found and and make a tutorial:

PHP Code:
package sample;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class 
Main extends Application
{
    @
Override
    
public void start(Stage stage)
    {
        
Label label = new Label("Welcome to JavaFx");

        
Group root = new Group();
        
ObservableList list = root.getChildren();
        list.
add(label);

        
Scene scene = new Scene(root500300);
        
scene.getStylesheets().add(getClass().getResource("a.css").toExternalForm());

        
stage.setTitle("JavaFX Label");
        
stage.setScene(scene);
        
stage.show();
    }
    public static 
void main(String[] args)
    {
        
launch(args);
    }

a.css
PHP Code:
.label {
    -
fx-font-size22px;
    -
fx-font-family"fantasy";
    -
fx-text-fill#77ff67;
    
-fx-opacity0.6;
    -
fx-background-colorred;

***********************************************************
id:
PHP Code:
package sample;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class 
Main extends Application
{
    @
Override
    
public void start(Stage stage)
    {
        
Label label = new Label("Welcome to JavaFx");
        
label.setId("alabel");

        
Group root = new Group();
        
ObservableList list = root.getChildren();
        list.
add(label);

        
Scene scene = new Scene(root500300);
        
scene.getStylesheets().add(getClass().getResource("a.css").toExternalForm());

        
stage.setTitle("JavaFX Label");
        
stage.setScene(scene);
        
stage.show();
    }
    public static 
void main(String[] args)
    {
        
launch(args);
    }

a.css
PHP Code:
#alabel {
    
-fx-font-size22px;
    -
fx-font-family"fantasy";
    -
fx-text-fill#77ff67;
    
-fx-opacity0.6;
    -
fx-background-colorred;

***********************************************************
PHP Code:
package sample;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class 
Main extends Application
{
    @
Override
    
public void start(Stage stage)
    {
        
Label label = new Label("Welcome to JavaFx");
        
label.setStyle("-fx-background-color: green;");

        
Group root = new Group();
        
ObservableList list = root.getChildren();
        list.
add(label);

        
Scene scene = new Scene(root500300);
        
        
stage.setTitle("JavaFX Label");
        
stage.setScene(scene);
        
stage.show();
    }
    public static 
void main(String[] args)
    {
        
launch(args);
    }

***********************************************************
PHP Code:
package sample;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class 
Main extends Application
{
    @
Override
    
public void start(Stage stage)
    {
        
String styles =
                
"-fx-background-color: #c8fff8;" +
                        
"-fx-border-color: #0000ff;" ;
        
Label label = new Label("Welcome to JavaFx");
        
label.setStyle(styles);

        
Group root = new Group();
        
ObservableList list = root.getChildren();
        list.
add(label);

        
Scene scene = new Scene(root500300);

        
stage.setTitle("JavaFX Label");
        
stage.setScene(scene);
        
stage.show();
    }
    public static 
void main(String[] args)
    {
        
launch(args);
    }


***********************************************************

Last edited by turay; 01-05-2018 at 02:47 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Y'know CSS was to kill off HTML table layout? Well, second time's a charm: Meet CSS Grid LXer Syndicated Linux News 0 04-01-2017 07:03 PM
LXer: GTK+ 3.20 to Feature Massive CSS Changes, Port Most Widgets to CSS Nodes LXer Syndicated Linux News 0 11-22-2015 06:30 PM
LXer: Making GTK3 themes – Part 2: The gtk.css and gtk-widgets.css file LXer Syndicated Linux News 0 07-24-2012 01:50 PM
CSS - Is there a way to put several lines of HTML into one line using CSS? Chronothread Programming 12 01-05-2011 06:06 AM
HTML/CSS/JS: Problem with <p> not having an absolute position with CSS. RHLinuxGUY Programming 7 03-03-2007 12:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration