JavaFX 2.0 :: Sizing Width Of ComboBox Based On Items
Apr 16, 2015
I have a ComboBox -- just a simple ComboBox with string items.
My string items aren't very long (5 letters max), but the ComboBox shows quite wide relative to my strings. So I would like to size my ComboBox to the size of my strings.
I messed around with setting the CellFactory of the ComboBox, and have the Cells produced by the CellFactory set the preferred width of the cells to some constant like 100. That worked in terms of changing the size of the ComboBox to the preferred width of 100.
But what I really want to do is to compute the preferred width from the string items. For that I need to be able to compute how wide a string item will be when rendered. And I guess that depends on the font size used by the ComboBox to render strings, which probably depends on the platform (OS X different to Windows?).
Returning true from getScrollableTracksViewportWidth() makes the table (or other Scrollable) size its width to match the viewport. I need the opposite: for the viewport to expand its width to accommodate the table (of course, limited by the constraints imposed by the scroll pane's container's layout manager) without reducing column widths i.e. setAutoResizeMode(AUTO_RESIZE_OFF).
I have achieved this by overriding
getPreferredScrollableViewportSize(): JTable table = new JTable() { @Override public Dimension getPreferredScrollableViewportSize() { return new Dimension(super.getPreferredSize().width, super.getPreferredScrollableViewportSize().height); } };
Now when the scroll pane is added at BorderLayout.CENTER and the frame is pack()ed, all columns of the table are displayed, without need for a horizontal scrollbar.
If I have a comboBox full of id's - is it possible that when I choose said id (click it) it will then transfer over into my textField where I can use that as a prefix for my filename ...
(The file can be created just by having a name in the text field it doesn't need to already exists) ...
This program is for a swimming pool filling service company. They charge 2 cents per gallon and $50 per hour to fill a pool. The truck can fill at a rate of 730 gallons per hour.
Create the Pool class that calculates the cost to fill a pool based on it's Shape, length, width and depth. (Input order is S L W D)
The pool class will need data fields for String shape, double length, double width, double depth, static double GallonsPerSqFoot = 7.4805, static double price per gallon = .02, static double FillingFeePerHour = 50.0, and static double FillingRate = 730gal/hr.
Create a No-Arg constructor and a constructor that accepts the non-static values, and has the methods: getShape, getLength, getWidth, getDepth, getGallons, getHours, getFillingFeePerHour, getHourlyCost and getTotalCost.
At the end of the class, create a main() method that asks for the input and returns the output based on the Pool class gets.. methods.
The shape options are oblong or rectangle. (A round pool would be oblong with the same width and height, a square pool would have the same width and height)
Example Output An oblong pool 18.00 feet long by 12.00 feet wide and 5.00 feet deep will use 6923.10 gallons of water and take 9.48 hours to fill. The total cost will be 612.65.
- The Instance Text box and SAVE button should be disabled. When the pop up appears. - The Instance Text BOX gets enabled only when any selection happenes in COMBO Box - The SAVE button gets enabled only when COMBO BOX and INSTANCE TEXT BOX is filled. - Let the CANCEL button be enabled always.
I am trying to make a text based game. the game has been working perfectly setting up the rooms, first couple of commands, and running it. I am now trying to add items to it but every time it try to run the game it returns :
java.lang.NullPointerException at Room.addItem(Room.java:107) at Game.createRooms(Game.java:133) at Game.<init>(Game.java:28) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[Code] .....
Here are the classes that matter for this particular situation
import java.util.HashMap; public class Item { private HashMap<String, Item> itemList; private String name; private String itemDescription;
[Code] ....
I know that it is the line
itemList.put(item.getItemName(), new Item(item.getItemName(), item.getItemDescription()));
In the game class that is causing the nullpointer exception i just really cant figure out why that keeps happening and how to add the values correctly....
I'm using the tableview-component. The size of font of header is greater then that of cells. The problem is: the width of the column bases on the cell with the longest string and if the header-string is longer then the header gets truncated (it shows ellipsis) and I have to change the width of column manually. How could I solve this problem? The easiest way would be to compute the column-width on myself. I can't find any method in javafx, that would allow to compute the width of string in pixels. In Swing there is the FontMetrics class and Graphics class, so it is easy to get the width in pixels. Are there any pendants to this classes in JavaFX?
I would like to change the default skin of JavaFXapplication during runtime. How I can do this using ComboBox? Now I use this code to change the value:
setUserAgentStylesheet(STYLESHEET_MODENA);
Is there a way to change the skin in a run time?
Ref Set default skin in JavaFX with ComboBox - Stack Overflow
I have a combo box inside a table cell for each row. I have defined a value change listener for each combobox. Whenever the combo box value is changed, the selected item is placed inside a MAPVOBean. The problem i am facing is when the user scrolls Up and down the tableview , the change listener is fired even without clicking on it the explicitly, and this changes the my value in my data structure. How to handle this. The source code is attached.
My Model:
Person class
Has first name, last name and MAPVOBean.
Address is stored in a MAPVOBean. It has a map and key is house number and the value is the state where the house is. It is assumed that the person can have one house in each state.
Columns in table view:
Column 1: First Name Column 2: Last name Column 3: State combo box. This shows the state in which the person owns a house.
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package taleviewtester; import java.io.IOException; import javafx.application.Application; import javafx.fxml.FXMLLoader;
In the below example i'm trying to add a combo box inside a subscene. But it is not working correctly .If I select a value from the combo box ,it's is not set in the combobox and the combobox values are not displaying properly.
I am developing a form with ComboBox as a subject (the user can choose one from the list , or type one) and TextArea where the user can write his notes (attached a picture). The user using a virtual keyboard (touch) to enter any characters.
I am using the append method to append the next Char to the TextInputControl class (both Combo and TextArea Inherit from it). When I try to deletePreviousChar() in the TextArea it works, but in ComboBox it fails
I put some System.out.println() to see what is the problem and it seems that with the ComboBox the class is loosing the Caret position after every action
Here is my code: (Look it also as a attached picture)
public void changed(ObservableValue<? extends String> observable, String oldVal, String newVal) { if (newVal != null) { if (lastNodeInFocus instanceof TextArea) { switch (newVal) {
[Code] ....
Here is the Debug results: CB = Combo TA = TextArea B=Before A=After , the numbers are the caret position (also attached as a picture )
CB - append B 0 CB - append A :1 CB - append B 0 CB - append A :2 CB - append B 0
Switching from Swing to JFX 8, I am trying to find out how to do something I would normally do in a super-simple ListCellRenderer, i.e. customize the String displayed for an item. I tried this:
ComboBox<Integer> combo = new ComboBox<>(); combo.getItems().addAll(1, 2, 3); combo.setCellFactory(new Callback<ListView<Integer>, ListCell<Integer>>() { @Override public ListCell<Integer> call(ListView<Integer> param) {
[Code] .....
However, when I do this, the customized String is not used for the selected Item (rather the standard toString() value of the item). Apart from that it is no longer selectable using the mouse (I submitted a bug report for this at [URL] .... but that is not really the point of my question.
Anything else I have to do to make sure the selected item is also rendered using the custom cell or is there a different mechanism for this?
I have noticed a strange behavior of Combobox element. The number of visible rows is not the same established by setVisibleRowCount() method. It happens when changing the items list dynamically. The following example reproduces it. I think it is Javafx 8 bug. I have tried unsuccessfully to trigger some event indirectly to refresh the combobox drop down.
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class TestComboBox extends Application { private int count;
I think this might be the reason as this comboBox is not recognized at the import to the scene builder library. I can show up the import dialog of custom controls, but my custom ComboBox is not showing up. All other implementations are there correctly as they are loaded from my customControl.jar file
I use the ComboBoxListViewSkin for the functionality to scroll to an item in the combo as a user types a letter on the keyboard.
I do this by:
/** * This method scrolls the itemView of the items to the first item starting * with the given char or string * * @param pressedKey */ public void scrollToChar(String pressedKey) { String value = pressedKey.toUpperCase(); for (Object userEntry : getItems()) {
[Code] ....
I really need to show up my custom Combo in the scenebuilder, as otherwise the rest of my fxml is not editable in sceneBuilder 2.0 ....
I want to synchronize a List<String> with the selected items of a ListView. In the real project, I want to synchronize the selected items of a TreeView and the selected images of a galery (custom control).
In most cases, the program works as expected but sometimes there are some issues.
- For example, when I launch the application and select all the items with Ctrl-A, the event { [One, Two, Three] added at 0, } is fired so the list of strings contains incorrectly 4 elements [One, Two, Three, One].
- Another example, when selecting all the items (with Shift+End), two events are fired { [One] removed at 0, } and { [One, Two, Three] added at 0, }, that's correct. But when I remove the last element with Shift-Up, 3 events are fired { [Two] removed at 1, }, { [Three] removed at 2, } and { [Two] added at 1, } and an exception is thrown:
java.lang.IndexOutOfBoundsException: toIndex = 3 at java.util.ArrayList.subListRangeCheck(ArrayList.java:1004) at java.util.ArrayList.subList(ArrayList.java:996) at com.sun.javafx.binding.ContentBinding$ListContentBinding.onChanged(ContentBinding.java:111)
We can write JavaFX application in JavaScript using Nashorn Engine, but you have to run application with command line like:
> jjs app_all.js -fx
So I wont know how can I deploy application that let you click on and lunch application or make it self-contained application packaging using package tools of JDK 7 Update 6 or later.
JScrollPane scrollPane = new JScrollPane(); contentPanel.add(scrollPane, BorderLayout.CENTER); tbl = new JXTable(); tbl.setColumnSelectionAllowed(true); tbl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tbl.setEditable(false); scrollPane.setViewportView(tbl);
The problem is that when it gets filled, all the columns are squashed together to fit into the jxtable. I expected the columns to be adjusted according to the width of the column header or column value (which ever is wider) and then for a horizontal scroll bar to be displayed that will enable me to scroll left or right.
how to set the columnwidth in csv file using javacode.
I used FileWriter class to upload data into the csv file but csv file is taking default width while showing content. Is there a way to set the fixed column width or set width dinamically based on value?
I was suppose to create a simple Java program for calculating the area of a rectangle (height * width). Then check the user’s input, and make sure that they enter in a positive integer, and letting them try again if they enter in a negative number. (I'm not sure how to get them to try again.
I am suppose to use an "if" statements and indeterminate loops to achieve the solution. The program will have the following requirements:
1. Ask the user to enter in both a height and width (as an integer) 2. If the user enters in a negative number, display an error 3. If the user enters in a negative number, give them another chance to enter in the correct value 4. Calculate the area and display to the screen once two positive integers have been entered.
import java.util.Scanner; public class RectangleAreaCalc { public static void main(String[] args) { int length; int width; int area;
Any way to get my Java window to open with a certain width and height. I've been googling and haven't found to much valuable information. Here is what I have so far.
import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class JavaWindow{ //Bring up the frame. private JFrame f = new JFrame("JavaWindow");
[Code] ....
When you compile that it runs a small window. I would like that window to be bigger when the file opens.