user-interface,javafx , How to make javafx label fit text?

How to make javafx label fit text?


Tag: user-interface,javafx

I have a dialog window for adding records to the table. As far as I don't want to create for example 10 fxml files for each table I have only one:

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<?import javafx.scene.layout.ColumnConstraints?>
<GridPane alignment="BASELINE_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="300.0" hgap="10" vgap="10" xmlns="" xmlns:fx="" fx:controller="com.{...}.gui.dialogs.AddingDialogController" fx:id="addingDialogPane">
        <ColumnConstraints hgrow="ALWAYS" minWidth="50.0" prefWidth="100.0" />
        <ColumnConstraints hgrow="ALWAYS" minWidth="50.0" prefWidth="100.0" />        


        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />

and dinamically add elemnts depending on which kind of record user wants to add. The problem is that when user opens adding dialog he see the following: enter image description here

and that is the problem. Elements covers each other. If I set GridPane's min width to bigger value I get another problem: enter image description here

the big empty space on the left. How to fit elements to the pane correctly without so big empty spaces?

UPD: here is the method used to add elemnts to the pane:

public void setAgent(Agent agent) {

        addingDialogPane.add(loginLabel, 1,2);
        addingDialogPane.add(login, 2, 2);
        addingDialogPane.add(extUidLabel, 1, 3);
        addingDialogPane.add(extUid, 2, 3);
        addingDialogPane.add(passwordLabel, 1, 4);
        addingDialogPane.add(password, 2, 4);

        addingDialogPane.add(confirm, 1, 5);
        this.agent = agent;


The column (and row) indexing start at 0. So your column constraints apply to columns 0 and 1; you have added elements to columns 1 and 2. So the text fields just get default column constraints, and the empty column 0 is set to grow always. Add elements to columns 0 and 1 and I think it will work.


JavaFX subclassed Button - How to make Label update work?

I want to have several JavaFX Buttons that update one Label in my Application with text. For testing purposes it's just Button Text. What I did at first worked fine and looked like this: String Text = "..."; public void kons() { System.out.println("Works..."); System.out.println(Text); Tekst.setText(Text); Button G4 = new Button("Spadantes");...

Javafx Tableview dont show data of ObservableList

i have a Problem mit the Tableview in JavaFX. I know there are some other posts in the forum, but i checked them and tried to use the solutions, but nothing work for me ... I have 3 Classes. One Version class, the data model. The Class which populats the...

Updating UI From a background thread on iOS

On iOS, its well documented that the UI should never be updated from a background thread. Rather the main thread should be the sole interface to update the UI. My Question is why? Is it because UIControls are not thread safe and hence there is always the possibility of main...

FX - Suggestions for aligning CheckBox in Grid

Converting from Swing to FX here. We have some CheckBoxes where the Label appears on the left side of the CheckBox. We are accomplishing this by calling setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); The problem is that in some GridPanes, we'll have a Label in column 0 with a Node in column 1 on row...

tablelist label color while mouse hovers

I've configured the background color of some lables of my tablelist by using the columnconfigure $ColumnIndex -labelbgmethod. However, the background color changes while the mouse hovers over the labels. I couldn't find any -activebackground method and I wish the background color will stay the same even when the mouse hovers...

What is wrong with this JavaFX/FXML custom component?

I am learning to write FXML custom components for use with JavaFX 8 and Scene Builder. I wrote the FXML file shown below but Scene Builder will not open it, giving me the message "Open operation has failed" due to the exception: javafx.fxml.LoadException: mycustomcomponent.TicoTeco is not a valid type....

How to change the color of treeitem expand and collapse arrow in javafx?

I have got some trouble with treeitems of a treeview. There are expand and collapse icon-arrows, when you have child-treeitems. I only know how to change the background-color of this expand/collapse icons. But I don't know how to change the color of the arrow. .tree-cell .tree-disclosure-node { -fx-background-color: #CCCCCC; }...

Getting a mouse position with JavaFX and Event

I'm trying to get the position of a mouse click in my JavaFX application. I have an EventHandler as so: EventHandler<Event> mouseHandler = new EventHandler<Event>() { @Override public void handle(Event event) { String eType = event.getEventType().toString(); if(eType.equals("MOUSE_PRESSED")){ //mouse position } } }; which is called on mouse press, release and...

Full Screen overlay without back/home/menu button

I have this function to show a fullscreen black overlay on my activity. To mimic screen off behaviour. private void showBlackOverlay() { Dialog dialog = new Dialog(this,;; } But still back/home/menu buttons are visible. How can I hide them? I need it to work on older versions of...

JavaFX8 : Single Controller for 1+1popup scene (Solved)

After following the tutorial at, I have a functioning popup window, however, I am having difficulty figuring out how to interact with it with a controller. From the tutorial, I got the impression that there is to be a shared controller between the two FXML files, but I'm having...

How to convert excel data to json at frontend side

I want to convert some excel data to JSON. Plan is to get my excel file from D drive, read data and make some UI for this. Can any one please help me out? Data is like this :- country year 1 2 3 4 Netherlands 1970 3603 4330 5080...

Change background color of viewcontroller but not top area with clock

I want to make my whole ViewController grey except I want the top area where it shows CARRIER and the current time to remain white. Is the only way just to stick a View that covers everything except that area, and set it to grey, or is there some way...

How to make a Javafx Image Crop App

I am building an application for my colleagues to crop image. I use FXML with Scene Builder to build the GUI. The user click a button to choose a image from his computer. Then, the image is shown in the GUI. User can zoom and move in the pane. At...

JavaFX - how to get background color of Tab, Button, etc

Problem description: I can't get background of object in JavaFX. I don't mean Shapes, but normal Nodes like Buttons, Tabs and others. I don't know how to access to theirs background color. What I want? I am developing IDE and I want to run Color animation on tab with file...

Customisable iOS Interface

I am currently developing an iOS app that can be used by different clients keeping pretty much the same interface for all of them. I would like to make this interface somehow “customisable” without having to change the storyboard for every client but I am not sure how to do...

UISpec4J tests in Eclipse are not found

I am trying to run tests using the UISpec4J library, but Eclipse says it can not find them. I have tried restarting Eclipse, cleaning the project, etc. The class gives no errors and I have followed the examples given on the website. package; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test;...

Opening frame that is under the JavaFX program category

Most of program is using JFrames throughout the application for all the different windows that can appear. However, I have to play an instructional video for the user inside a JFrame. I couldn't find a way to do this, so I had to make a JavaFX program. Is there a...

How to identify web actions in JavaFX webview?

I need to catch the actions like clicks, drag, right-click, double click etc, that are done by the user on JavaFX web view. How to achieve it?

Open a file from user input in python 2.7

How would I open a file by asking for user input? After raw_input("PROMPT") requests filename.txt from the user, I get the error code: TypeError: coercing to Unicode: need string or buffer, file found which tells me I need to convert the user input to a string, or format it a...

MessageBox won't work when handling WM_DESTROY event from DialogBox

While elaborating an answer for another question (by myself), I've come up with the idea of using a MessageBox to report the result of my dialog box. It is a WinAPI modal dialog box created with the DialogBox() function. However, I noticed that handling WM_DESTROY in the dialog's procedure function...

Using transparent images and repeat

I have a tab and would like a custom image to underline part of the text in the tab. I have 3 images, left image transparent for 14px and then 1 pixel wide of colour, a right image that is the reverse of this, and a 1 px wide image...

How to accomplish 3 horizontal line menu in fxml

I want to create menu like "Firefox (Three horizontal line - top right side) Menu". I don't know how to create this line of overlay menu in FXML. Have anybody any idea about this? Thank a lot....

How would I connect to a MySQL database back-end from an Android device's application? [closed]

I have developed a standalone JavaFx application in Netbeans with a MySQL database back-end which I want to also package as an APK package for running on Android. How would I go about porting the MySQL database script it uses to Android?

JavaFx TreeCell how to expand nodes after one second

i'm implementing the Drag&Drop on a generic TreeView. My purpose is to expand a folder during DragEntered event after a second of stationing, actual code: setOnDragEntered(e -> { TreeItem<TreeItemContent> enteredItem = getSourceItem(e); if(model.isFolder(enteredItem)){ enteredItem.setGraphic(images.getFolderOpened()); enteredItem.setExpanded(true); } e.consume(); }); desired: setOnDragEntered(e -> { TreeItem<TreeItemContent> enteredItem = getSourceItem(e); if(model.isFolder(enteredItem)){ if(dragDuration >= 1...

Converting from Pixel Coordinates to UI Coordinates in Unity

Does anyone know how to convert from Pixel Coordinates to UI Coordinates and vice-versa in Unity? Let's say for example I want to click somewhere on the screen with the mouse, and a UI Image to be at that click position. If I do this won't work: Image img =...

Python MVC style GUI Temperature Converter

#The view ( import tkinter import Controller class MyFrame(tkinter.Frame): def __init__(self, controller): tkinter.Frame.__init__(self) self.pack() self.controller = controller #Output Label self.outputLabel = tkinter.Label(self) self.outputLabel["text"] = ("") self.outputLabel.pack({"side":"right"}) #Entry Space self.entrySpace = tkinter.Entry(self) self.entrySpace["text"] = ("") self.entrySpace.pack({"side":"left"}) #two convert buttons self.convertButton=tkinter.Button(self) self.convertButton["text"]= "Fahrenheit to...

How to avoid user to click outside popup Dialog window using Qt and Python?

I created a Dialog window using Qt Creator and Python. I would like that Window stays on the top of my Gui AND avoid users to click outside that Dialog Until this dialog was closed.

How to keep GridBagLayout from changing the size of a button

In my FlashCardPanel class, I have a subpanel,LabelPanel, with a Grid Bag Layout. It consists of a constructor with an edit button, a button to "flip" the card, and the label to display the term/definition. My problem is that every time I click my "Flip" Button to display the definition...

Javafx TextField pseudoClassStateChanged method not working

I'm setting PseudoClass to TextField to highlight them when error occurs. The red border appears around TextField only when I click mouse inside it (to put text value), but I need to show border all time. there is how I sets border: element.pseudoClassStateChanged(PseudoClass.getPseudoClass("error"), true); It worked just fine till last...

JavaFX TextField : Automatically transform text to uppercase

I have a JavaFX TextField control on my FXMl that looks like this... <TextField fx:id="input_search" onKeyPressed="#keyListener" prefHeight="25.0" prefWidth="197.0" /> I want to automatically change all characters to uppercase when the user is typing. The code in my controller : public void keyListener(KeyEvent event){ //maybe transform the pressed key to uppercase...

FXML: ClassNotFoundException

I'm very new to JavaFX and I'm having problem using my custom class in FXML. The console keeps giving me this exception when trying to load main.fxml: ... 1 more Caused by: java.lang.ClassNotFoundException: sample.View$BoardPane at ... I created BoardPane class as a subclass of FlowPane in package sample.View and...

How to change Eclipse IDE GUI icons?

Elipse icons are ugly. Fact! I would like to replace the icons with more flat, monochromatic and minimalist icons, but I can't find documentation on how to change icons from Eclipse's user interface. How could I do this? It's needed to recompile eclipse?...

Difference between Pane and Group

My question is simple : in JavaFX, what is the difference between a Pane and a Group ? I can't make any difference ... Thank for your answer...

Rotate line segment with Button

I have a line which has points (x1,y1) and (x2,y2). I wanted to attach a Button to it, it should align with the line by rotating based on the line segment points. I need some help in calculating the rotation angle for the Button.

Overlapping Items in WPF ItemsControl

I am having a problem with DataTemplates used in a WPF ItemsControl. I want to be able to "bring forward" any of the items in the list so that they are on top of everything else in the list, but haven't had any luck. Here's a simple example that illustrates...

How is the Point2D “angle” method to be understood?

I thought I'd use the Point2D class for calculating e. g. the angle betwen 2 points instead of creating a utility method. It turned out, it's not usable at all. Code example: Point2D p1; Point2D p2; p1 = new Point2D(0, 0); p2 = new Point2D(10, 10); System.out.println( "Point2D: " +...

UI4J - Get the entire document innerhtml

Is there a way to get the innerhtml for the entire page, including html, head, body and so on. I am only able to call page.getDocument().getBody().getInnerHTML() ... there is no page.getDocument().getInnerHTML() ... shouldn't there be ?...

How to analyze incoming message (JavaFX on Android)

I ported my JavaFX application to my Android device. I want my application to read incoming SMS messages and store it in a database. I found several questions here in StackOverflow but I don't know how to implement in a JavaFX approach. Please help!

Updating ac value for Qtimer

I am using qt tool for mini2440. I make a gui for i2c adc having starti2c and stopi2c. All things are working well: it reads value of signal when starti2c button press, but I want this value to be updated. I know that Qtimer can be used, but how can...

Chart JavaFX, my hover Label are hidden by the edges of chart

I have a problem again with the JavaFX Chart : D Context : I had Popup/Label on my chart to display the value on hover : JavaFX LineChart Hover Values (Jewelsea answer) Problem : But when the point are near the edges of chart, the popup is hidden by them....

QGraphicsScene on a QMainWindow

Still new to Python so I'm trying to get a QGraphicsScene to be inside a a QMainWindow. Right now the way I have it coded is that two windows will appear but I only want one window to appear with the QGraphicsScene "inside" the QMainWindow. Here is my code: import...

Form controls not showing

I'm making a console application that shows a form. I created the form from scratch. When I run the program, the form shows, but the controls I added don't show. My code: using System; using System.Windows.Forms; using System.Drawing; namespace form { public class main { public static void Main() {...

Java - Enforce TextField Format - UX - 00:00:00;00

Please see below image of the UI of my current application Currently, I am enforcing Data Format of the text fields in the back end. If the RegEx does match (00:00:00;00), it will throw an error. My question is from a UX perspective, is it possible to make the input...

close sub-window without closing main window PyGTK in python

I am creating a gui in python with PyGtk and I would like to create a sub-window that branches off from my main window but unlike a dialog the user will be able to interact with the main window without having to close the sub-window. The following code was demonstrated...

Multi-Threading error when binding a StringProperty

I have a question about multi-threading and the binding of a StringProperty. I have a class CacheManager, which contains a Thread which updates my cache with the changes on the server. Now, I want to notify the user with a text and percentage of the progress (which are a Label...

How to put an image on another image in python, using ImageTk?

I want to put an image in front of another one, then use this combined image as a button's background image in Tkinter. How can I do it? I am free to import Tkimage, Image. Clarify: I want to stick this on the center of this so that something like...

pyqt gui locked when calling cython function from

In PyQt4 I want to execute code with no lock gui. I use QThread and emit signal for gui update. But if i call cython function in gui will be locked. class Runner(QtCore.QThread): iter = QtCore.pyqtSignal(int) def __init__(self): QtCore.QThread.__init__(self) def do_something(self): beg = time.time() s = 0.0 while time.time()...

Android : Creating GUI programmatically at run time in java

I have to create number of buttons and textbox, etc. depending upon a certain number. For ex: if the number = 5, I need to create 5 buttons, and if its value is 10, I need to create 10 buttons. To achieve such a functionality, the conventional xml GUI won't...

Filter JDK Bug System by JavaFX

Is there a way (filter settings, etc) to see only JavaFX related bugs in the JDK Bug System? Also, the Reporter names seem to be gone. Now I'm "J. Duke", I guess like everyone else that doesn't have an acount there. So how do I find the bugs I reported?...