Creating a JavaFX label with a border radius of 20

I need help with creating rounded edges for two labels in my interface. I want the first label (Hello) to have rounded edges on the top left and top right, and the dummy label to have rounded edges on the bottom right and bottom left.

I've attempted using -fx-border-radius: 30; in CSS, but it doesn't seem to be working as expected. Please review the class definition for the Hello label. Any assistance would be appreciated!

package com.binaryname.view;
public class Main extends Application {

private ConversionController conversionController = new ConversionController();

private PopupWindow keyboard;

// Rest of the code...

This is my interface.

The issue seems to be related to border-radius in the CSS file named style.css. Here's the complete CSS code:

.center-text-area *.text {
    -fx-text-alignment: center;
}

.helloLbl{
    -fx-border-radius: 20 20 0 0;
    -fx-background-radius: 20 20 0 0; 
}

#hello-radius{
    -fx-border-radius: 20 20 0 0;
    -fx-background-radius: 20 20 0 0;
}

// Rest of the CSS styles...

Below is the FXML structure:

<?import javafx.scene.layout.BorderPane?>

<BorderPane xmlns:fx="http://javafx.com/fxml/1">
    <!-- TODO Add Nodes -->
</BorderPane>

Answer №1

To achieve a border radius effect, I created a new background and set the cornerRadius value accordingly. Here is an example of how it was done:

    TextField tf = new TextField();
    Color color = Color.rgb(150,200,150);
    CornerRadii corners = new CornerRadii(8);
    Background bg = new Background(new BackgroundFill(color, corners, Insets.EMPTY));
    tf.setBackground(bg);

Answer №2

If you're looking to round a specific edge, follow this example

.customLabel{//custom label id
        -fx-border-radius: 20 20 0 0; 
        -fx-background-radius: 20 20 0 0; 
/* defining the radius for top-left, top-right, bottom-right, and bottom-left corners */
 }

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

Ways to display dynamic content within a div using Bootstrap's vertical tab through a click event in PHP

I have been working on displaying static content in a div using Bootstrap vertical tabs, similar to this: Link: However, I am facing an issue with showing dynamic content in a div using a Bootstrap vertical tab through a PHP click event. I have been try ...

Ways to create a sequential appearance of elements through CSS animations

Can you help me achieve a wave effect for elements appearing one by one using CSS animation (jQuery)? Currently, all the elements show up at once and I want to create a wave-like motion. Any assistance would be greatly appreciated. $(window ...

The error message "Could not locate method testCompile() for parameters" appeared in the AndroidStudio while using Robo

I'm encountering an issue while attempting to perform basic unit tests using Robolectric and AssertJ in AndroidStudio. I've included Robolectric, AssertJ, and JUnit in my build.gradle file using the testCompile method. However, when trying to run ...

In C++, the division between class definitions and implementations is emphasized, unlike in JAVA where this distinction is not

I have an assignment where I need to assess the best approach based on GRASP principles. I came across a helpful resource that partially answers my question: Why are header files and .cpp files used in C++? However, I am curious about how effective C++ i ...

What could be causing my difficulty in locating an HTML element using jQuery/JS string interpolation?

In my project, I have a set of div blocks each identified by a unique numerical id. For instance: https://i.sstatic.net/lYod8.png One of the tasks in my project is to select the 29th element following a specific chosen element. For example, if I choose t ...

Close the ionicPopup by tapping anywhere

Currently, I have implemented an ionicPopup that automatically closes after a certain time limit. However, I am wondering if there is a way to configure it to close with a single or double tap anywhere on the screen instead. While I am aware that setting a ...

Sending passwords in the HTTP request body during the spring season. Securely storing user passwords in Java

After creating a node rest API using firebase to handle user login authentication with a JSON payload containing username and password, I am now faced with the challenge of integrating this functionality into my spring application in a secure manner that d ...

Does defining the width and height of images go against the principles of material design?

Currently, I am immersed in a project utilizing material design. In this context, I find myself contemplating the size of an image that has been hard-coded as (200x200). I am curious to know if this approach aligns with the principles of material design. ...

Creating a unique look for unordered list items in a dropdown navigation

I'm currently working on creating a drop-down menu using nested unordered lists. The functionality of the menu is all set, but I'm running into some styling issues. The main link that triggers the drop-down should have a blue background with whit ...

The MUI Grid design features information displayed on the left side, accompanied by an image placed directly to the right

In the React MUI V5 sample code below, I am creating a profile page layout with details of a person displayed on the left side of the page in label/value format. My question is how to position an "IMAGE" entry (assume it's a 300px x 300px profile ima ...

Center the radio buttons regardless of the length of the text

My dilemma lies with 3 radio buttons and their corresponding labels - while 2 of them are aligned perfectly beneath each other due to their matching character lengths, the middle one extends further making it look misaligned. Check out this fiddle. Below ...

Styling a div to wrap around an image

I'm working with an image element that has the style attribute set to style='width:40%;height:40%'. My goal is to add a div around this image that will automatically adjust its size to wrap around the image. However, when I try inserting the ...

Eliminate the Material Stepper heading

Is there a way to remove the header navigation from the material stepper? I've tried using the following CSS code without success: .mat-horizontal-stepper-header-container{display: none} You can view the stepper on Stackblitz by clicking this link: ...

The connection between the layout of dropdown menus and the way data is handled in forms

I have discovered three different methods for creating dropdowns that can be used in forms: 1) Utilizing HTML with "form-dedicated" attributes such as select and option value="" 2) Implementing the Bootstrap framework with div classes like "dropdown", Butt ...

Tips for shifting objects from a horizontal row to a designated vertical column when switching to a smaller display

I am currently utilizing bootstrap to enhance my website layout for mobile view. The main challenge I'm facing involves transitioning items from a row to a column in a specific order. In this case, I have two items in a row and I would like the first ...

CSS - How to specify a class within an id using syntax

How can I target a specific tag within an ID using the class name in selector syntax? For example, how can I make the inner "li" turn red in the code snippet below? <html> <head> <style type="text/css"> #navigation li ...

Executing Selenium Grid using Java as a typical software application

I am currently in the process of developing a Java project to conduct website testing using Selenium. I have successfully created nodes, hubs, and run tests using TestNg on Eclipse. However, I desire to enhance automation by inputting URL, ports, and inst ...

Creating various media types with Spring and Jersey

Recently introduced to REST and tasked with creating a Rest Controller that requires a file name as a parameter to display its contents. See the code snippet below: @RequestMapping(value = "/paths", method = RequestMethod.GET, produces = "application/pdf" ...

Implementing a parallax scroll effect using CSS and dynamically updating the background-position value with JavaScript

How can different Y position percentages be dynamically assigned to multiple layered background images in CSS using JavaScript so that they update as the page scrolls? <style> body { background-image: url(img/bg-pattern-01.png), ur ...

Configuring static files in Django for hosting a website in production mode

I have been attempting to serve my static files from the same production site in a different way. Here are the steps I took: First, I updated the settings.py file with the following: DEBUG = False ALLOWED_HOSTS = ['12.10.100.11', 'localhos ...