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


How to make javafx label fit text?

Question:

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 com.sun.javafx.scene.control.skin.IntegerField?>
<?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="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.{...}.gui.dialogs.AddingDialogController" fx:id="addingDialogPane">
    <columnConstraints>
        <ColumnConstraints hgrow="ALWAYS" minWidth="50.0" prefWidth="100.0" />
        <ColumnConstraints hgrow="ALWAYS" minWidth="50.0" prefWidth="100.0" />        
    </columnConstraints>
    <rowConstraints>        

    </rowConstraints>
    <children>


    </children>
    <padding>
        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
    </padding>
</GridPane>

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(AgentNameLabel,1,1);
        addingDialogPane.add(name,2,1);
        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;
        name.setText(agent.getName());
        login.setText(agent.getLogin());
        extUid.setText(agent.getExt_uid());
        password.setText(agent.getPassword());
    }

Answer:

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.


Related:


Getting a mouse position with JavaFX and Event


java,javafx
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...

Opening frame that is under the JavaFX program category


eclipse,video,javafx,jframe,mp4
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...

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


java,javafx,fxml
After following the tutorial at http://www.javafxtutorials.com/tutorials/switching-to-different-screens-in-javafx-and-fxml/, 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...

Multi-Threading error when binding a StringProperty


java,multithreading,javafx,javafx-8
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...

JavaFX TextField : Automatically transform text to uppercase


java,javafx,fxml,keyevent
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...

How to convert excel data to json at frontend side


excel,user-interface
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...

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


python,user-interface,tkinter
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...

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


java,regex,user-interface
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...

Difference between Pane and Group


javafx,group,pane
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...

Customisable iOS Interface


ios,iphone,xcode,user-interface,customization
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...

Converting from Pixel Coordinates to UI Coordinates in Unity


user-interface,unity3d
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 =...

FX - Suggestions for aligning CheckBox in Grid


java,checkbox,javafx,grid,alignment
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...

How to identify web actions in JavaFX webview?


javascript,webview,javafx
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?

JavaFx TreeCell how to expand nodes after one second


javafx,nodes,expand,treecell
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...

How to change Eclipse IDE GUI icons?


eclipse,user-interface,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?...

Javafx Tableview dont show data of ObservableList


user-interface,javafx
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


ios,user-interface,background,thread-safety
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...

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


java,animation,colors,javafx,background
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...

Open a file from user input in python 2.7


python,python-2.7,user-interface,user-input
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...

Full Screen overlay without back/home/menu button


android,user-interface
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, android.R.style.Theme_Black_NoTitleBar_Fullscreen); dialog.show(); } But still back/home/menu buttons are visible. How can I hide them? I need it to work on older versions of...

How to keep GridBagLayout from changing the size of a button


java,swing,user-interface,layout-manager
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...

UISpec4J tests in Eclipse are not found


java,eclipse,user-interface,testing,uispec4j
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 com.health.gui; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test;...

How to analyze incoming message (JavaFX on Android)


java,javafx,javafx-2,javafx-8,javafxports
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!

MessageBox won't work when handling WM_DESTROY event from DialogBox


c,user-interface,winapi
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...

pyqt gui locked when calling cython function from QThread.run


python,user-interface,pyqt,cython,qthread
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 QThread.run 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()...

QGraphicsScene on a QMainWindow


python,user-interface,pyqt4,qgraphicsscene
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...

What is wrong with this JavaFX/FXML custom component?


java,javafx,javafx-8,fxml,fxmlloader
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: java.io.IOException: javafx.fxml.LoadException: mycustomcomponent.TicoTeco is not a valid type....

Using transparent images and repeat


css,user-interface
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...

Android : Creating GUI programmatically at run time in java


java,android,user-interface,dynamic
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...

How to make a Javafx Image Crop App


java,image,canvas,graphics,javafx
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 TextField pseudoClassStateChanged method not working


java,javafx
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...

Rotate line segment with Button


math,javafx,geometry,coordinates
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.

Change background color of viewcontroller but not top area with clock


ios,user-interface,uiviewcontroller
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 accomplish 3 horizontal line menu in fxml


menu,javafx,overlay,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....

UI4J - Get the entire document innerhtml


java,javafx,ui4j
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 ?...

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


charts,javafx,popup,linechart
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....

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


javafx,treeview
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; }...

Overlapping Items in WPF ItemsControl


c#,wpf,xaml,user-interface,datatemplate
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...

Filter JDK Bug System by JavaFX


java,javafx,openjdk
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?...

close sub-window without closing main window PyGTK in python


python,user-interface,pygtk
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...

JavaFX subclassed Button - How to make Label update work?


java,javafx
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");...

Form controls not showing


c#,forms,winforms,user-interface,user-controls
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() {...

Updating ac value for Qtimer


qt,user-interface,adc
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...

tablelist label color while mouse hovers


user-interface,tcl,tk
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...

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


javafx,geometry
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: " +...

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


java,android,mysql,javafx,apk
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?

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


qt,user-interface,python-3.x,dialog,qt-creator
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.

FXML: ClassNotFoundException


javafx,fxml,fxmlloader
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 java.net.URLClassLoader.findClass(URLClassLoader.java:381) ... I created BoardPane class as a subclass of FlowPane in package sample.View and...

Python MVC style GUI Temperature Converter


python,user-interface,python-3.x,model-view-controller,tkinter
#The view (GuiTest.py) 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...