Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

form design

 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Friends,

I have made my first form using jgoodies. Kindly see the code and suggest that whether I have done it in the recommended manner. Is there any better way to build buttons. The problem I am facing is that the buttons OK and Cancel are getting leftmost aligned with no space beneath them, i.e. they touch the wall of the frame. Here is the code

Kindly help.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put:

inside your "buildbutton()" method to add some space around the buttons so they won't touch the edges of the frame.
 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nathan. It works.
But Can you kindly tell me what can we do so that the Buttons are placed exactly in the bottom center. I mean instead of left 10 and right 10, they take the center of the frame.

Also if you can throw some light whether it is necessary to get another panel as I have done obtained panel1 for building buttons. Was it not possible to append buttons in the Panel itself in the buildscreen method using some builder.append(Buttons). Why I had to take another panel was because I had defined panel as having three columns and if i would have appended there, it would not have got centre aligned. Is there some way out because a lot many times it is required to place some input fields then some buttons then again some input fields then some buttons. Can it be not done in a single panel using the Formlayout.

Thanks.
 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more problem is there. I am calling this addparty program from a combobox inputverifer i.e. when a user selects "Add a party" option displayed in the combobox, then this form is called and displayed. The form is getting displayed but gets hidden behind the form of the combobox from where it is being called and secondly I want that it should get displayed in the center of the form from where it is called. Again this is not happening. Kindly help.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the way that I found to center the buttons and add them to the main panel -



As for the second problem, the one where you are attempting to "launch" the form from a combobox and it's not being displayed - it sounds like you need to look into CardLayout - this allows you to set up a "stack" of Panels and call methods to move between them.
[ October 19, 2007: Message edited by: Nathan Pruett ]
 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.

But can you kindly explain the column specifications you have used ( I am new to jgoodies).

"right :p ref,3dlu,left :p ref:grow"

ref stands for what and why you have used it and how the buttons will be centered.

Also what does the addglue() method does.

thanks.
 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also what does
builder.append(buildButtons(ok, cancel), 3);
will do. I mean why you have used 3 i.e.for what purpose.

Thanks
 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also I dont feel that card layout would be required. What I want to do is open a sub-window when the combobox item in the main window is selected. While the sub-window remains open, the main-window should be visible but not accessable i.e. it should loose focus and should not gain focus until and unless the sub-window is closed. This sub-window is addparty window. The window is getting opened, but the thing is that it gets hidden behind the mainwindow.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"right :p ref,3dlu,left :p ref:grow"


These are the same column specifications used in your original program - "right:pref,3dlu,left:pref:grow" - when they got posted in the forums, the :p parts of the string got changed into smiley faces sticking out their tongues(as in your original post). I edited my post to turn smilies off, but guess I forgot to take the spaces out.


addglue()

addGlue() adds a "glue" component to the layout - glues are invisible, and they expand to take up extra space - so the glues on each side pushed the buttons to the center.


builder.append(buildButtons(ok, cancel), 3);

the 3 tells the layout to let the button panel take up all 3 columns of your original layout.


What I want to do is open a sub-window when the combobox item in the main window is selected. While the sub-window remains open, the main-window should be visible but not accessable...


What you should do then is use JDialog or JOptionPane... JOptionPane is probably the simpler choice, and if you use that you won't have to worry about the buttons at all in your panel - JOptionPane will take car of the buttons for you.
 
Anand Shrivastava
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your worthy guidance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic