Zachary Wright

Greenhorn
+ Follow
since Aug 04, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Zachary Wright

Michael Dunn wrote:1)
can't help with grouplayout (I don't use it), but a BorderLayout should do what you want
JLabel at BorderLayout.WEST (set JLabel to JLabel.LEFT)
JButton with image in a JPanel(default FLowLayout should be OK), add the panel to BorderLayout.CENTER (panel is to take up additional space)
JLabel at BorderLayout.EAST (set JLabel to JLabel.RIGHT)
don't worry about sizing - refer to (2)

2)
gridlayout 'cells' are identical in size, so if the size of the panel is not an exact multiple of the number of cells, there will be a gap left over.
generally, calling frame.pack() will fit all in nicely



You're absolutely right about #2..it seems that I was over complicating things by trying to set the size on everything. Turns out that setSize being called on a JButton is quite a bit different that setPreferred size...I didn't know that.

However, number 1 is still giving me issues. I took your advice and placed my reset button inside of another JPanel, then added it to the statPanel, but the button still expands to take up the entire space. :\

Not sure what the deal is there.

EDIT: Aha! It appears that JButton has two methods, setContentAreaFilled and setBorderPainted - which I can use to make the button invisible.

Thanks for the help, my gui looks perfect now and I can start on making the actual game. :cool:
15 years ago
I am currently working on my first program that will use a graphical user interface. I am attempting to create a Minesweeper look-a-like, being as true to the original as possible. I haven't programmed any game logic yet, but I am nearly finished with setting up the layout of my components.

Although it will technically work in the state I have it, there are a few things bugging me that I cannot seem to figure out.

First, I will post a few of the important code samples I will be discussing:



Now, my questions.

1. I have read through almost all of the swing tutorial, including the section on how to use the 'GroupLayout' layout. I am using this to set up the stat panel, with the counter/reset/timer button/labels. I want the two labels to be at each end, and the reset button to be in the middle. (I realize they aren't animated yet, I'll do that later). I thought that by grouping each one in a parallel group, and using the LEADING, CENTER, TRAILING constants, this would do that for me. However, as you can see, they like to group up in the middle:



Can anyone tell me what I'm doing wrong with the group layout here? Is there another layout that will function in this way, perhaps more simply?


2. I am using the grid layout to set up the mine field. It works great - except for a gap it wants to put in between the panels edge and the grid's edge. I have tried to make the panel smaller to accomodate for this gap - no matter how much smaller I make the panel, that gap remains there. Here is an image of what I'm talking about:



Anyone with experience using gridlayouts know what is wrong with my code?

Again, all of the code governing these panels is located in the big code block I posted.


I appreciate any help, this has been frustrating me for a while.
15 years ago
I'm using Struts 1, and I have a question I think will be pretty simple to answer. I've tried several different ways to do this, to no avail.

Is there any way to have the results of a changeAction open into a new window? I thought that putting a target="_blank" in my link would cause the window to open, then the server to send back the information into that window, but from what I can tell, the changeAction is happening before the new window can even be created.

I'm thinking I'm going to have to use AJAX to do this, but it's going to mean a large rework of a lot of things I've already done, and since I don't really know AJAX yet, it's going to take a lot of time to learn how to use it, so I thought I would ask first.
16 years ago
Thanks very much for the help, it did end up being a problem with the way the tiles were set up, and things seem to be working well now with my form parameters being set correctly.
16 years ago
Thank you for the help, I have taken your advice and created a new form and action for my quick search jsp.

I thought for sure this would solve the problem, but oddly it didn't. I'm wondering if I'm doing something else wrong.

In my jsp I have a few javascript functions, one to read in keystrokes in case a user clicks "enter", to perform the search. The other builds an "onclick" string and does a changeAction using that onclick string. The form parameter for the current "view" in the menu is passed in in the URL, something like "blah.do?step=quickSearch&submitAction=quickSearch¤tView=<view>"

The four possible search parameters are set in text boxes, like:
<html:text property="searchCustomerName" style="font: verdana; font-size: 12px;" />

However, whenever I type something into that box (or any of the other boxes), and hit the submit button, which calls the javascript function which builds the onClick and does the changeaction, they are always null. The getter and setter methods are all spelled correctly, and my IDE (Intellij IDEA 7.0.3) doesn't find any errors on my jsp page or in the form and action.

The quickSearch jsp is still a tile, being placed on each of the other four pages created by the other jsps, which use a different form.
16 years ago
Hello, this is my first topic here, and thanks for deciding to read it.

I'm currently working on a project using Struts 1, and as a Struts newbie I'm having some trouble managing one of the pages that I'm working on. I've spent a lot of time trying to learn how struts works and how to use it effectively, but like I said, I'm still a newbie to it.

I have five jsp's created, four of these jsp's are the four possible views for when a user is navigating a 4-tabbed menu on a certain part of the website. They all use the same form, but each jsp allows the user to enter and manage different information.

The fifth jsp is a new one I'm creating, which offers a sort of "quick search" functionality, that the user can use to stay on the same screen and "view", but load up a different set of data. I already have the search functionality created. My problem is that I want this new, quick search jsp to use the same form and the same action that the other jsp's are using, since they are all closely related. I just needed to add a few form parameters to the form, and a new step to the action, and I thought I was good to go. The new quicksearch jsp is a tile, when I use to show it at the top of the other views, represented by each of the other jsps. I did this because I didn't want to replicated the exact same code four times.

However, I am having a problem. Since I have two jsp's using the same form on the same page, I think that when a user submits the "quicksearch" form, the parameters are immediately reset by the second instance of the same form on that page, and none of the parameters are getting passed to the action. Or something to that effect, I have print statements inside the action class, and they are consistently printing "null" for all the form parameters entered into the search bars. I have checked the getter and setter methods and my tags, and everything looks correct.

Now I'm just wondering if it's possible to even do this, have two jsp's using the same form on the same page. If not, is it possible to move the <html:form "/..."></form> tags into a base file that sort of wraps all the other jsp's?

Any help is greatly appreciated, I've been agonizing over this for a few days now.


Thanks,
ZW
[ August 04, 2008: Message edited by: Zachary Wright ]
16 years ago