Grids in Java- Equivalent - java

Is there any grid equivalent object in java ?
I tried using j tables but they don't have all the functionalities needed.
in C# there is a grid object which saves a lot of work. i was wondering if there is any similar object in java.

As far as I know, there is no grid like data structure or collection available in Java. Though you can implement a grid like structure in Java with help of a two-dimensional array.
In case of AWT you might want to use the GridLayout class. Hope this helps.

Definitively the equivalent is JTable, however, if you're trying to create functionalities seems to Grid in C#, you will need to do a little bit extra effort, with swing you should focus on events and add the corresponding listeners in order to add the desired features on it.

Related

Can we assign both classes and id to Javafx Controls

Hi there JavaFx community. So I recently shifted from html/javascript to Javafx and using scene builder to create my UI.
My question is, like in html we could assign classes and id to an element, can we do the same in JavaFx, ie assign multiple textfields and buttons the same class? According to what I have seen we cannot assign classes in javafx. I would appreciate if someone could shed some light on it.
I am asking this as having classes for GUI elements in html makes life so much easier so I'm just dumbfounded if javafx doesn't allow us to do this.
Also in that case, what would be good alternative ways around this issue.
Thanks heaps..
You can define css classes in JavaFX just like you can in HTML. Have a look at this tutorial: http://docs.oracle.com/javafx/2/css_tutorial/jfxpub-css_tutorial.htm See: "Creating Class Styles"

How to make a board in Java using 2D arrays and JTable ?

What I have in mind is to make a JTable. The model will use the 2D array's columncount and rowcount to set the JTable's rows and columns.
What I cant figure out is how do I go around making fields for these cells in the table?
Example fields like - Status(boolean), Image etc. So by having these fields I want to edit the cells when the application is running and show the user the updates.
I have tried to make a 2D object and add fields in there. But it doesnt seem to work.
What would be a good way to build this?
I am using swing to build this.
This isn't a very specific question so that limits the answer I can give - from what you want to do, I'd suggest
Making sure you understand how the Model-View-Controller paradigm works in Swing
Looking into the Observer / Observable framework and how it fits in with MVC
Extending some sort of Swing Component to reflect changes in your model.
Once you've covered the above you should find that implementing what you want to do is reasonably trivial, and that you can ask more directed questions that will get better responses.

Creating a Grid in Java

As a way of learning Java, I'm writing this little application for grade schoolers to practice basic math. The idea is that the kid does any number of math problems, as long as they are in the app, it just continues to throw problems at them until they click a 'Done' button. When they decide to be done, I want a new JFrame to come up that will show them all of the problems they attempted, along with their answer, and whether they got the problem right or wrong.
The advice that I am looking for is what is the best way for me present these results. I looked into the GridLayout and the GroupLayout, but I don't think that these are exactly right. I did something similar in VBA for Excel, and there I just ran a for loop with one iteration for every problem they attempted. Each iteration would add a row of labels to the frame with the elements of the problem displayed in the various labels. I tried this in Java, but I'm not even able to get the labels to even display.
So before I get all specific and start posting my code, I want to ask a bigger question, which is "what is the best method to create a view like this?" Often, I go off in one direction only to waste time before somebody suggests a totally different (and better) approach.
Thanks!
(edit: here's an image of how I did this in Excel. I'm trying to repeat basically the same thing in Java)
One simple way to make that design would be to use a mix of components. You could have a bunch of JLabels and JPanels stacked in a vertical FlowLayout. The grid you have described would be best designed in a JTable, something like the below:
If you like tables like Excel then, Java provides JTable class to create tables, if you want.
Tutorial : http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

Multi Dimensional array to JTree in java

i want to assign a multidimensional array to jtree. how can i do this?
here is sample of an array:
ROOT:{ FolderA : {FileA,FileB} , FolderB: {FileA,FileB} } ....
Also i want to determine files and assign icon to them.
You must get model from your jtree and then operate on it. Here you have working example
Here's a nice article showing how to use org.netbeans.swing.outline.Outline for this. There's more in this answer. Ordinary extensions of TableCellRenderer or the RenderDataProvider interface make it especially easy to customize the appearance of rows in the tree.

Drag and Drop and identify locations with java

I'm trying to do something quite simple, but I'm having a hard time finding good examples on the net to what I want specifically.
I'd like to somehing very similer to what it's here:
Dao
It's a simple game called DAO and I just need to have a background image with 16 squares (4x4) and drag and drop the images (pieces) on each square to the others. I'm developing the interface using swing and I simply want to know a good place to find tutorials for such implementations or a simple suggestion on how to do it.
Thanks in advance
Shameless plug:
have a look at my simple example via my google project
http://code.google.com/p/jchronos/
There is code to drag list item across list boxes. Same should be applicable to JLabel
Look at sources
http://code.google.com/p/jchronos/source/browse/trunk/src/org/jchronos/ui/QuadrantPanel.java
http://code.google.com/p/jchronos/source/browse/trunk/src/org/jchronos/ui/ArrayListTransferHandler.java

Categories

Resources