Creating a Sleek MenuBar in JavaFX

At the top of my BorderPane, I have added a MenuBar containing a "File" Menu and a "Close" MenuItem:

https://i.sstatic.net/5TAGS.png

I want to make it appear thinner like the MenuBars in most software applications, similar to the image below:

https://i.sstatic.net/xw3cm.png

It seems like a simple task, but as a beginner, I'm having trouble finding information online. I don't know what keywords to use when searching (not many helpful results for queries like "javafx menubar height", size, styling, etc.)

Answer №1

By incorporating the following selectors into your style sheet, you can reduce the height of each menu element:

.menu-item { -fx-padding: 1 5 1 5; }
.menu { -fx-padding: 1 5 1 5; }

https://i.sstatic.net/p7TSR.png

To eliminate padding from all context menus, you may also include the following:

.menu .context-menu { -fx-padding: 1 1 1 1; }

https://i.sstatic.net/YRtpI.png

You can additionally decrease the font size by using these lines of code:

.menu-item >.label {-fx-font-size:9;}
.menu >.label {-fx-font-size:9;}

https://i.sstatic.net/BtcY2.png

Moreover, to remove the left and right padding of the MenuBar and decrease spacing, utilize the following:

.menu-bar {
  -fx-padding: 0 1 0 1;
  -fx-spacing: 1;
};

https://i.sstatic.net/aABJK.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble aligning two divs horizontally on the same line in Bootstrap 4

I am facing an issue with my HTML code where I have two div elements that are supposed to be horizontally aligned, but the second div is appearing underneath the first one. To fix this, I tried using bootstrap classes for alignment. <div class="c ...

Modifying CSS using jQuery in a PHP While Loop

I've been racking my brain trying to solve this issue, experimenting with different approaches but so far, no luck. Question: How can I dynamically change the color of a specific div within a PHP while loop using jQuery after receiving an AJAX respon ...

Test Container initialization encountered an error during TestNG BeforeSuite phase

Encountering issues when executing the web driver module in conjunction with the test container setup. BaseTest.java package com.testautoamtion.webdriver; import org.openqa.selenium.chrome.ChromeOptions; import org.testcontainers.Testcontainers; import or ...

Incorporate unique color variables from the tailwind.config.js file

I am working on a project using nextjs and typescript, with tailwind for styling. In my tailwind.config.js file, I have defined some colors and a keyframe object. My issue is how to access these colors to use as background values in the keyframe. Here is ...

Can you please explain the purpose of the white space in the HTML code?

Currently, I am working on developing a mobile application, and as I start adding styles, I notice a mysterious blank space that seems to be appearing out of nowhere. Can anyone provide any insights or suggestions to help me troubleshoot this issue? https ...

How to retrieve the value of an element as a String using XPath in Selenium with Java

My experience with Selenium and Java is quite new. I have a screen value that contains double quoted data (Test) which I need to select and replace with a different value. "value": "Test", "createDateTime": "2016-08-23T15:37:06+0100", "channel": "P ...

Using Jquery to encase an element in a div while scrolling down and removing it while scrolling up

After some experimentation, I've managed to wrap an element inside a div using jQuery. My next challenge is to wrap it as you scroll down and unwrap it as you scroll up. Do you think this is achievable? Although I have succeeded in wrapping it while ...

What is the distinction between using `string.equals(value)` and `value.equals("string")` in the Java programming language?

Is This a Duplicate Question? Exploring the differences between myString.equals(“aString”); and “aString”.equals(myString); in Java In certain instances of Java coding, why does "string to compare".equals(input_value) appear instead of input_v ...

Access information from multiple div elements using JavaScript data-attributes

Having trouble retrieving data-attribute values from multiple divs with the same class when clicked. The goal is to display the data value of the clicked div. function playSound(e) { const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`) ...

I must modify the initial statement to appear in bold from the paragraph with the use of JavaScript and CSS

Mr. XYZ and Mrs. ABC are known for their integrity. They own a stylish car. In the next paragraph, I would like to emphasize the first sentence by making it bold, We admire our exceptional leader J.K.L. He shows great potential. In this section, I wan ...

Floating action button within a collapsible panel

I am having trouble placing a fixed-action-btn inside a collapsible body. It keeps appearing in the bottom right corner of the page instead of within the collapsible itself. How can I ensure that the button stays inside the body? Check out this link for r ...

Searching efficiently across multiple columns in HibernateBy combining multiple columns in

@Entity // marking the Book class as an entity bean for Hibernate @Indexed // Indexing Book @AnalyzerDef(name = "ngram", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters = { @TokenFilterDef(factory = StandardFi ...

Looking to learn how to utilize the setInitial method in Java programming?

Can someone help me write a method in Android Studio using setInitial(int[] x) to set the first 3 indices of an array to specific values (10, 100, and 342) and then return the modified array? I am struggling with this assignment and need assistance within ...

What could be causing maven install to throw an error in relation to npm?

After merging two branches, an error occurred: [ERROR] The goal com.github.eirslett:frontend-maven-plugin:1.6:install-node-and-npm (install node and npm) on project frontend failed to execute because it couldn't extract the npm archive located at & ...

Discovering the presence of a td Element in Selenium WebDriver with Java

CSS Code <table class="adminlist" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr data-bind="if: RowCounts>0, attr: {StatusId: Id, DescName:Name}" statusid="2" descname="Abandoned"></tr> <tr data-bind="if ...

Tips for eliminating the glowing effect when pressing down on the thumb of the material ui slider

Visit Material-UI documentation for Slider component. Despite setting the disabled flag for the entire slider, the thumb continues to show a halo effect when clicked. ...

A guide to deserializing a Map in Java with keys as integers

I've encountered an issue while using the Flexjson API for serializing and deserializing a map with integer keys. When deserializing, the keys are automatically converted to strings. Is there a way to preserve the keys as integers? Below is an exampl ...

An easy way to attach a Contextmenu to a specific element

I have implemented a scrolling feature for one of the div elements in my Application. Inside this div, there is a templated table with over 100 rows. Users are able to add or delete rows using a contextMenu. The contextMenu offers 4 options - AddTop, AddB ...

Clearing out all the rows in DefaultTableModel

I am facing an issue where I need to delete all the rows from my DefaultTable. After researching online, I came across two common methods for deleting rows, but unfortunately, neither of them seem to work in my case because these methods are not available ...

Looking for a solution to a problem with your vertical CSS/jQuery dropdown menu

My web app features a vertical CSS menu that is working correctly except for one minor issue. When I mouse out on all elements with the class a.menutoggle, the last dropdown menu remains open. I am struggling to find a solution to hide it. Can someone plea ...