So I have an application developed in C# that creates a bunch of controls on command from a button click. It does a lot of control creation but I've scaled it down to just the first two of a set that it creates, for simplicity. In the picture below you'll see that I have pressed the Create button (which goes invisible upon clicking) and it made 16 (ability to scroll to see more) text boxes and combo boxes each respectively aligned with each other.
Now, I know I should have thought of developing this in a cross platform environment before production, but disregarding that, my main problem now is emulating this application in Java using Swing and AWT GUI objects.
I do have the ability to create the text boxes all in line as shown.
In addition I have the ability to create the combo boxes where I'd want them to be, in line as shown.
However, once I try to do a dynamic create with both, then the location/positioning gets really messed up.
Is there an attribute or property that I'm missing? The code for the location positioning is below... They don't have any other attributes turned on or off that are different from their defaults.
panelContainer.add(newComboBox);
newComboBox.setSize(95, 20);
newComboBox.setLocation(miniCount * (newComboBox.getWidth() + 10) + 80, 45 + levelCount * 170);
panelContainer.add(newTextBox);
newTextBox.setSize(95, 20);
newTextBox.setLocation(miniCount * (newTextBox.getWidth() + 10) + 80, levelCount * 170);
The miniCount and levelCount variables just make sure that we have only 6 (miniCount) items per row and to go to the next row if we need to (levelCount). The rest of the magic numbers are for positioning of course.
The text boxes are AWT TextFields boxes. The combo boxes are AWT Choice boxes.
EDIT:
The Java application and C# application are separate. They ultimately run the same algorithm, but I'm just have trouble making the GUIs act the same.
Related
I have a Java Swing App which adds JInternalPanes on button click into a JDesktopPane. However, everytime I add a new JInternalPane to the DesktopPane, they all are overlapping and I always have to move the newest one to the side in order to see the previous one again.
Is there any way I can set the position of the newest one slightly to the right of the previous one?
I came up with this workarround but this just looks weird and there is probably a better alternative.
public void createMarket() {
this.appWindow.getDesktopPane().add(new Market(this.restClient, this.websocketClient, this.appWindow.getSymbolTextField().getText(), this.appWindow.getSelectedInterval()));
if (this.appWindow.getDesktopPane().getAllFrames().length > 1) {
JInternalFrame previousFrame = this.appWindow.getDesktopPane().getAllFrames()[this.appWindow.getDesktopPane().getAllFrames().length - 2];
this.appWindow.getDesktopPane().getAllFrames()[this.appWindow.getDesktopPane().getAllFrames().length - 1].setLocation((int)(previousFrame.getLocation().getX() + 100), (int)(previousFrame.getLocation().getY()+100));
}
}
There is no code in the Java platform that would tile or cascade JInternalFrames - you will have to write that yourself.
Here is some example of cascading internal frames:
http://www.java2s.com/Code/Java/Swing-JFC/JDesktopPaneCascadeDemo.htm
Note that the frames are placed using setBounds(). For tiling them, you'd have to check how many there are, decide about the amount of rows and columns, calculate the coordinates and call setBounds() again.
NOTE: This is not homework. My Swing application was homework, but it's already completed. I'm doing this for my own knowledge to get a better understanding of JavaFX and Scenebuilder.
I created a Swing application that contained a 27x27 grid. Upon clicking "Normal Setup", only the center square is visible.
I am attemtping to translate everything into JavaFx, and I am using Scenebuilder. I'm still learning how to use this, and I'm unsure if I have my GridPane placed correctly (Notice how creating a 27 x 27 grid makes it go beyond the bounds of the parent). I can work on that later.
What I would like to know is if you can set all of the attributes for each node across the board. I had to go into my FXML file and manually change each node size in the 27x27 grid. This will get exhausting eventually. Surely there is a way to do this?
As you can see each node will have a Label template, and it will only be visible when a certain ant accesses it.
In my Swing version, an example of setting everything for all nodes looks like so:
setPreferredSize(new Dimension(ColonyView.NODE_SIZE, ColonyView.NODE_SIZE));
where the "NODE_SIZE" is:
public final static int NODE_SIZE = 96
Any help would be appreciated.
Select a node in your GridPane and press STRG + A
You can use CSS to set the yellow background. See https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html for details.
I have list of objects which I want to display in GUI.
Each object is:
1) complex (it has a number of fields), thus I need several widgets to be used in GUI component which corresponds to 1 model object,
2) editable. Its properties can be changed by user via GUI (buttons, input fields and checkboxes which lay within component which corresponds to 1 model object).
How conceptually can I do this? Which UI framework and which widget to use?
Coming from android development, I have no experience in java desktop applications (by the way, in android this task can be easily accomplished by means of standart instruments (listview + its adapter)).
I have tried swing framework with its JList and JTable. But it turned out that elements within JList's cells are not editable (say, I cannot press buttons if there are a few inside Jlist's cell). The same applies to JTable.
I have googled for swing, swt, javafx etc, but didn't find direct answer how this task can be accomplished.
Any help is appreciated.
P.S. It is not an option to use JTable with several columns. In fact, I want to have list of JForms or JPanels (in swing terms).
I am attempting to create a a java GUI for use on Zedboard with the 7" touchscreen display. The GUI I am creating is supposed to mimic exactly (though scaled down) a physical console with many interactive buttons.
My question is what would be the best method in making the buttons interactive, my first thought was to cut out the buttons of the console and have each one a separate image that can be set as interactive, but I feel there may be another simpler method.
Thanks
LDY
For the console mimicking, you could take an image of the entire console and then listen to touch event at specific points in the image which corresponds to a button. Based on where the touch event occurs, you could do different actions.
For this you need to get the coordinates of the touch event and check if it corresponds to any of the buttons on the console.
I'm running a large Java Eclipse project and when it starts up, I see 3 pop-up windows tiled on top of each other, as so:
I need to have them start up separated positions, as I'm always testing the program and dragging the windows. Can I somehow put them all in a bigger GUI window(pane)?
Use setLocation() method
windowName.setLocation(location_parameters);
passing the 'null' as an argument will make the window center.
There is another way,
setLocationRelatedTo(item_to_relate)
method. this will locate them according to the existing things like JLabels, existing windows, etc.
Can I somehow put them all in a bigger GUI window(pane)?
You presently have 3 JFrames, I think.
You could change this to 3 JPanels in one frame.
You would use a layout manager to arrange the 3 JPanels the way you want.