Create an array of JButtons with the Netbeans 6.5 GUI Builder - java

I want to create an array of JButtons with the GUI Builder (not actually writing the code, but drawing it). I can only figure out how to change the name of the element, not add it to an array.
Thanks.

http://wiki.netbeans.org/FaqGuiControlArray

I think you'll find doing much "programmatically" will go beyond most GUI builders, other than for specific programmed-for exceptions.

Related

Creating a GUI Class in Eclipse

What I'm thinking of doing is creating a class for my little subview, so I can use it over and over again. Specifically, in my project, I need a colored rectangular and a label, and between those subviews those are the ones gonna change. Thus, I want a class that represent that two components as one component.
I'm trying to use swing. Before, I used acm package which gave me convenient way of doing it, but I can't solve that problem with swing. So, the problem starts here, I couldn't figure out how to create a custom GUI class for a subview.
I want to put them in a for loop later, so I want to handle the case in once rather than writing for 20 times manually.
Any help would be appreciated,
Create your custom class so that it extends a JPanel. From there, you can add your common subcomponents, which sets each one up by passing parameters through the constructor, and then implement any common behaviours with methods on that class.
You could try Window Builder plugin for eclipse for drag and drop editor. You could try to figure what's going wrong by organizing you objects.

Dynamic reference to JComponents?

First Java project - solving a Sudoku puzzle. Used SDK to create GUI first (bad idea?). GUI has 9x9 grid of square JButtons. Added handlers (81!) such that 'click' cycles values '_','1',...'9'. Named buttons in grid to reflect position (also painful). To solve puzzle implemented 9x9 array of Tile objects. Tiles to mirror state of respective JButtons (text value, etc). Want to use array of Tiles to solve puzzle. To use get/setText methods to r/w from array to/from JButtons. Hit wall!! Can't find way to reference JButtons. Hoped to create String representing JButton variable name (easy enough) then magically convert (type casting?) to reference JButton object. Not possible? A String is a String is a...? I have an object in memory (JButton) I can't reference dynamically? Approaches seen (tic-tac-toe, etc.) create an array of JButtons to access by index. Don't want to do this as it takes away from simplicity of using swing. The SDK generated source code is ~2000 lines already! Use hash to map objects to objects? Ideally each Tile object will map to respective JButton when created. Hopefully enough detail here to explain what I am 'trying' to do. Is this case where pointers would be nice? Is this a downfall of using SDK for GUI? Shortcoming in Java? Can anyone recommend approach to this (tricks or tips)?? Thanks!!
Array of Objects extending JButton is way to go. Learned much here and many thanks to all who contributed!! For newbie to Java to think an extensive swing UI is an easy approach is foolish. Took me a few weeks to learn basics of JComponents. I still use 'Window Builder' but only for the most basic interface. Want to challenge a new student? Let him/her try to tackle Sudoku as first project! Now that I have conquered this UI I feel on top of the world and no problem is beyond my reach! THANKS AGAIN!!

Java swing - creating text field on button's place

When specific action is performed, I want to replace button with text field. I know that I have to call button1.setVisible(false); but I don't know how to create text field on the exact same place. I am using NetBeans designer, if you can give me a hint, how to add 2 components at same place, and switch between then, something like switching between layers in photoshop, if something like that is possible, would be great. Thanks
For many components in one space, use a CardLayout as see in this short example.

Is there a way to make a non deep copy of a JPanel

Alright I have a JPanel (I'm using NetBeans and swing) that I would like to make a copy of and use it in another tab, meaning it uses the same layout as the other panel but I dont want to make a deep copy of it. Cause if I make a deep copy of it when I change one I change the other. Is there any way to just make a copy of what it looks like without it having the ties to the original
Seems that you have misunderstood the word "deep copy" - a deep copy just has the effect of not being tied to the original, in contrast to a shallow copy, which leaves such ties.
Anyway, creating copies of whole Swing component trees is nothing which is really supported - it could be done by serialization, though.
But why can't you simply use the same code which created your original JPanel (with the components in it) and create a new one?
Here is method for solving the following problem without coding just using design views of JPanels/JFrames.
You can go to Navigator in design view select all JPanel components and copy them by typing ctrl+a and ctrl+c. Then create another one JPanel and in design view, just paste them with ctrl+v.
Result: You get all components same size, dimensions and positions with same properties and values. After you do this, you can easily change whatever you want by using properties of GUI forms.
You actually cannot make a copy of a Swing component that is tied to the original. Components can only share models.
You can make a clone of your panel which will be totally separate panel in no way tied to the original.
You're using Matisse UI-designer in Netbeans IDE? Then you can just select your designed JPanel, copy it to the clipboard and paste into the other form.

Is there a possible Control for this?

I'm currently using net beans with Java to work on a senior project. Essentially the program is going to create word search puzzles.
While I'm still a few weeks from needing a solution, I'm having difficulty thinking of a possible control that could display a word search puzzle (not to be mistaken for a crossword puzzle).
My initial thought would be to have a grid of subclassed JPanels stored in another subclass of JPanel [as a 2D array, or something].
You could then attach MouseListeners to the grid cell JPanels if you need to detect if they've been clicked on, or whatever
Might give you an idea
brainjar - Wordsearch (source at bottom of page)
What do you mean by control? Maybe something like a JTable + Custom ListSelectionModel

Categories