This question already has answers here:
In javaFx, Why do we need to call "getChildren()" when we add an element to a window?
(3 answers)
Closed 5 years ago.
For example if I were to add a line of code such as-
hbox.getChildren().add(calculateButton);
what significance does .getChildren hold and what happens if it not used in a program?
getChildren method is used to get the children components(such as checkboxes, buttons etc) in a container.
In your case, hBox is a container which can contain buttons, spinners etc. So getChildren lists the current components in hBox.
It is basically a list of components currently present in the container. By using add() you are adding a new component in that list.
Related
This question already has answers here:
Disable JButton focus border
(5 answers)
Closed 4 years ago.
i'm new there. My first issue:
When i start my GUI java swing application in Window Builder, first object is always selected
and when i click anything (button or anything) it's show like it's clicked and i don't want it to show. What command for this?
You should use this:
button.setFocusPainted(false);
java, swing, awt, remove focus from all objects
This question already has answers here:
Best way to store data between program runs in java?
(11 answers)
How can I save the state of my program and then load it?
(2 answers)
Closed 5 years ago.
For example, if I had checked a JCheckBox when I opened the program, how would I make the it remember the status of the checkbox so that the next time I open up the JFrame, the box stays checked.
I would also like to extend this question to other swing components like radiobuttons, color chooser, etc.
Attempted solution: The only way I can think of it is possibly making a new file so that the program can update and read the status of it and adjust the swing components when opened. However, this is too inefficient. I read online something about cookies but I am not too sure.
This question already has answers here:
How to draw a tree representing a graph of connected nodes?
(4 answers)
Closed 6 years ago.
Given a tree how one could approach to draw the same using Java Swing that what we draw in a simple piece of paper to understand a tree ? i.e. drawing all the nodes an values inside the node circle as well as threads to join the parents with the child and so on .The Structure will be like this :
From https://en.wikipedia.org/wiki/Tree_%28data_structure%29#/media/File:Binary_tree.svg
You can use JavaFX for that:
https://en.wikipedia.org/wiki/JavaFX
http://docs.oracle.com/javase/8/javase-clienttechnologies.htm
That's the newest Java GUI technology!
This question already has answers here:
How to count number of JCheckboxes checked?
(4 answers)
Closed 9 years ago.
I was wondering if there was a way to check the number of checkboxes checked in Java. I found plenty of instruction on how to do in in javascript but not Java. Thanks for you help!
A few options that I can think of-
Every time a checkbox is checked, increment a (global) counter in its listener. Decrement the counter when the checkbox is un-checked. So, at any given point in time, you know the number of checkboxes checked
Iterate through all the checkboxes and check how many of them are checked. It would be good if you create a collection of checkboxes that you would be using in your code
If the checkboxes are on different screens or in different classes, then you need to main counter at all places and sum them up whenever you want to know the number of checkboxes checked in your application
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Issue regarding dynamically loading Images in loop using Java Swing
Can any one tell how I would add images dynamically using for loop in JToolBar. I tried a lot but it didn't work for dynamic loading of images. I want to create ToolBar where I load images in a loop.
JToolBar is particularly well adapted to adding JButton instances each having a distinct Icon, so I would advocate using ImageIcon. Complete examples maybe found here, and more were cited in comments to an answer to your previous question.