• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Applet not displaying correctly

 
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have coded an applet which accepts name and occupation of use and displays the total characters entered on click of a button.
COde:


If you execute this code,you will notice that controls appears in a way which give a look of an Iron piece struck to an electro magnet in the center. I know it is something to do with constraints of the components, but I cant figure out what. I tried specifying weightx as 0.5 but that seperates the coponents in an ugly way. Can you suggest me how can I make the controls arrangement look pleasant.

Also, you will notice that on Enter button appears immediately below the Occupation label. Whereas accoding my layout arrangement it should leave some row space for the hidden fields.On entering values and pressing enter the hidden fields ,must become visible as per my codes logic. But it is not happening. For some reason it happens once the applet is resized.

Please guide me to fix these logic errors.



Thanks
 
Sheriff
Posts: 28413
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's try moving this to the AWT/Swing forum where there are more regulars to answer AWT questions. This one isn't specifically applet-related anyway.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your best bet is to use more than one layout manager in nested Panels (or JPanels if this were a Swing app -- which I recommend by the way). You can find the tutorial on how to use layout managers here: http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html

Also, when using GridBagLayout, don't forget to use insets and fills. e.g.,
 
Suvojit Chakraborty
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much for posting reply. I thought my post was erased as I could not find it in its original location.
I have read the suns document on Gridbaglayouts and learned a lot. But I have found it difficult to implement the things practically. It will be great if you can share some sources on gridbag layout which show practical examples and explains it in better way.
I have also executed your code and it looks perfect. However I dont understand why does your code's applet has grey background in which button is blue and labels are bold Where as in my case applet has white background, Please tell me what did you do in your code which makes it behave like this?? I could not spot any reason

Also I am posting my modified code in which I have set ipadx,ipady etc as per your suggetion, but still there are layout problems which are:
1. You will notice there is unwanted space is there between the rows, even though I mentioned them to be on consequent rows.
2. Also I dont understand why does the total char row which is hidden initially and is supposed to be displayed on click of enter, does not get displayed on pressing enter. It get displays when I resize the window or remove focus from applet and again gives focus to the applet. It seems to me that the paint process is not happening in this case but I dont understand why? I have made a call to repaint from inside the event handler.



Please help to fix the problem.

Thanks
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Suvojit Chakraborty wrote:I thought my post was erased as I could not find it in its original location.


Posts get moved around if there are other forums in which they would be a better fit. You can always find all your posts through the "My Posts" link at the top of the page.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Suvojit Chakraborty wrote:Thank you so much for posting reply. I thought my post was erased as I could not find it in its original location.
I have read the suns document on Gridbaglayouts and learned a lot. But I have found it difficult to implement the things practically. It will be great if you can share some sources on gridbag layout which show practical examples and explains it in better way.


You're welcome. One helpful tutorial is this one: Taming the GridBagLayout and others can be found through Google.

I have also executed your code and it looks perfect. However I dont understand why does your code's applet has grey background in which button is blue and labels are bold Where as in my case applet has white background, Please tell me what did you do in your code which makes it behave like this?? I could not spot any reason


Probably this is due to my applet being a JApplet, and thus a Swing GUI application rather than an Applet which is built with the older, less flexible and less robust AWT graphics library.

Also I am posting my modified code in which I have set ipadx,ipady etc as per your suggetion, but still there are layout problems which are:
1. You will notice there is unwanted space is there between the rows, even though I mentioned them to be on consequent rows.
2. Also I dont understand why does the total char row which is hidden initially and is supposed to be displayed on click of enter, does not get displayed on pressing enter. It get displays when I resize the window or remove focus from applet and again gives focus to the applet. It seems to me that the paint process is not happening in this case but I dont understand why? I have made a call to repaint from inside the event handler.


1. Some of your GridBagConstraint values seem randomly created. You'll want to read all tutorials you can find to help straighten you out on this.
2. I'm no expert in AWT but perhaps calling revalidate() in your action listener after you've called setVisible(true) but before you repaint you can get the layout managers to relayout components.
 
Suvojit Chakraborty
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Pete,

Thank you for your support. I did some more researchwork on layout and I am now in a better position. I fixed my code and it is ok now. I have understood weightx,weighty now. And I also realized that weightx,weighty is aint important as long as we dont strech applet area.

revalidate() works with swing. However I found that validate() can solve my problem.

My code now


I also think layouts can be mastered with more and more practical work. I will continue to do experiments with different components og GridBagConstraints to gain better command of the subject. I hope you will help in my silly doubts( if any)

if ever my post if being viewed by someone like me, then I would like to ask them to go through sun's tutorial first throughly and then refer this: this

Thanks again
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic