LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 09-22-2020, 09:14 AM   #1
kkoistinen
Member
 
Registered: Jul 2012
Posts: 42

Rep: Reputation: Disabled
JavaFX program doesn't locate CSS file


Hello everyone,

I am using Kubuntu 20.04 with Eclipse 2020-06. I am trying to learn JavaFX and have this problem with CSS files. My program code is as follows (actually code is from "Learn JavaFX 8"). My JavaFX version is 14 and Java version is 11.

Code:
public void start(Stage stage) {
		Button yesBtn = new Button("Yes");
		Button noBtn = new Button("No");
		Button cancelBtn = new Button("Cancel");
		
		HBox root = new HBox();
		root.getChildren().addAll(yesBtn,noBtn,cancelBtn);
		
		Scene scene = new Scene(root);
				
		scene.getStylesheets().add("/home/kkoistinen74/buttonstyles.css");
		
		stage.setScene(scene);
		stage.setTitle("Styling buttons");;
		stage.show();
When I run this program I get the following error:

syysk. 22, 2020 4:09:51 IP. com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged
WARNING: Resource "/home/kkoistinen74/buttonstyles.css" not found.

In the book there's suggestion to change Classpath. I have tried instructions given here:

https://howtech.tv/pc/how-to-set-and...path-in-linux/

without any success. The idea with the CSS is to change outlook of buttons in code and actually unmodified buttons are displayed. I tried to browse net for answers but couldn't find anything that works.

Yours

Kimmo

Last edited by kkoistinen; 09-22-2020 at 10:17 AM.
 
Old 09-22-2020, 10:07 AM   #2
boughtonp
Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 966

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738

You should probably specify which versions of JVM and JavaFX you're using.

When I was experimenting with JavaFX a couple of years back, I had this code to load the stylesheet:
Code:
Scene.getStylesheets().add( getClass().getResource( "ui/styles.css" ).toExternalForm() );
Where ui was a directory at the same level as the java file that line came from - no idea if it'll work for absolute paths, nor if newer versions of JavaFX have changed anything.


Last edited by boughtonp; 09-22-2020 at 10:09 AM.
 
Old 09-22-2020, 10:36 AM   #3
kkoistinen
Member
 
Registered: Jul 2012
Posts: 42

Original Poster
Rep: Reputation: Disabled
Quote:
You should probably specify which versions of JVM and JavaFX you're using.

When I was experimenting with JavaFX a couple of years back, I had this code to load the stylesheet:
Code:
Scene.getStylesheets().add( getClass().getResource( "ui/styles.css" ).toExternalForm() );
Where ui was a directory at the same level as the java file that line came from - no idea if it'll work for absolute paths, nor if newer versions of JavaFX have changed anything.
I already submitted the version. However I changed Eclipse settings a bit. Adding referenced libraries to project and including proper directory seems to help out with this problem. So the solution is:

Add (from Eclipse) the following: Java Build Path -> Libraries -> Add external class order. Now Eclipse can find the required CSS files for this project or programs under external class directories.

Last edited by kkoistinen; 09-22-2020 at 10:44 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
[SOLVED] JavaFX Css? turay Programming 1 01-05-2018 03:44 AM
LXer: GTK+ 3.20 to Feature Massive CSS Changes, Port Most Widgets to CSS Nodes LXer Syndicated Linux News 0 11-22-2015 07:30 PM
LXer: Making GTK3 themes – Part 2: The gtk.css and gtk-widgets.css file LXer Syndicated Linux News 0 07-24-2012 02:50 PM
CSS - Is there a way to put several lines of HTML into one line using CSS? Chronothread Programming 12 01-05-2011 07:06 AM
HTML/CSS/JS: Problem with <p> not having an absolute position with CSS. RHLinuxGUY Programming 7 03-03-2007 01:21 AM

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

All times are GMT -5. The time now is 08:09 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
Open Source Consulting | Domain Registration