DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Style a Stage in a Minimalist Way

Style a Stage in a Minimalist Way

Pedro Duque Vieira user avatar by
Pedro Duque Vieira
·
Sep. 15, 12 · Interview
Like (0)
Save
Tweet
Share
8.59K Views

Join the DZone community and get the full member experience.

Join For Free

there are various modes in which you can style a window in javafx. sometimes it may be interesting to style it in a minimalist way without any window decorations but only the ones provided by the os such as a drop shadow in windows 7.

first lets take a look at what javafx gives you. there are 4 ways to style your stage:

  • stagestyle.decorated – a stage with solid white background and platform decorations.

  • stagestyle.undecorated – a stage with a solid white background and no decorations .

this is basically just a stage with no decorations at all just a solid white rectangle with no borders  for you to paint on.

  • stagestyle.transparent – a stage with a transparent background and no decorations .

same as the above but with a transparent background instead of solid white.

  • stagestyle.utility – a stage with a solid white background and minimal platform decorations.

this one is similar to the stagestyle.decorated expect that the corners aren’t round, there is no minimize and maximize button and the close button is smaller. also it does not show up on the windows taskbar so it is not meant to be a top level application window but a secondary one.

so there is no provided way to style a top level window with only the os decorations. to achieve this you’ll have to create a window with no decorations using stagestyle.undecorated and style the top level container through css.

the following code sets the top level container borders as round and adds a drop shadow to achieve the windows 7 appearance:

-fx-background-radius: 6;

-fx-border-color: gray;

-fx-border-style: solid;

-fx-border-width: 1;

-fx-border-radius: 6;

-fx-background-radius: 6;

-fx-effect: dropshadow(three-pass-box, rgba(100, 100, 100, 1), 24, 0.5, 0, 0);

however, there is a problem with this code. the drop shadow will not be visible since it falls outside the bounds of the scene. for it to be visible you’ll have to provide some space around the top level container, you can do this using -fx-background-insets  which sets the insets of the container and -fx-border-insets which sets some space around the borders as well.

so the final css for a top level container with a style class of rootpane will look like this:

.rootpane

{

  -fx-border-insets: 23;

  -fx-background-insets: 23;

  -fx-background-radius: 6;

  -fx-border-radius: 6;

  -fx-border-color: gray;

  -fx-border-style: solid;

  -fx-border-width: 1;

  -fx-effect: dropshadow(three-pass-box, rgba(100, 100, 100, 1), 24, 0.5, 0, 0);

}

and the window will look like this:

(the logo, top header and close button are later additions, i.e. not a result of the css code above)

Container Drops (app) JavaFX Space (architecture) application Logo (programming language)

Published at DZone with permission of Pedro Duque Vieira, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Silver Bullet or False Panacea? 3 Questions for Data Contracts
  • The Real Democratization of AI, and Why It Has to Be Closely Monitored
  • Spring Cloud: How To Deal With Microservice Configuration (Part 1)
  • Implementing Infinite Scroll in jOOQ

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: