This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes help needed for swing questions. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "help needed for swing questions." Watch "help needed for swing questions." New topic
Author

help needed for swing questions.

Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

There are 2 questions i want to ask:-
1. Explanation:-
I create simple example of nested Jtabbedpane & ask question in swing section.
cointainer/components size & diamentions!
I try with java's default look & feel(which apply without writing specific code).
Then i use open source look & feel.jtattoo
For both i got different values for x,y axis.

I ask their 'contact us' & got reply that

the problem is that you want to get the bounds before you set the frame to visible. Bounds are calculated by the layout managers after the frame becomes visible.

So base on this i create more simpler example as below

--------------------------------------------------------------------------------------------
Scenario's
Case 1: As per Jtatto's peoples way
window.frame.setVisible(true); //location1 active other inactive
Working & "frame.setVisible(true);" is commented
i got answer

--------------------------------------------------------------------------------------------
Case 2: Code created by eclipse IDE's Windows builder drag & drop functionality.
window.frame.setVisible(true);is commented
Working & "frame.setVisible(true);" is active. //location2 active other inactive
i got answer

--------------------------------------------------------------------------------------------
Case 3:
Code created by eclipse IDE's Windows builder drag & drop functionality.
window.frame.setVisible(true);is commented
Working & "frame.setVisible(true);" is active. //location3 active other inactive.
i got answer:

--------------------------------------------------------------------------------------------
Case 4:
UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
Is active with window.frame.setVisible(true);
other are commented.(Location 2 & 3)
I got answer:

--------------------------------------------------------------------------------------------
Case 5:
UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
Is active with frame.setVisible(true); (at location 2)
other are commented.(location1 & 3)
I got answer:

--------------------------------------------------------------------------------------------
Case 6:
UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
Is active with frame.setVisible(true); (at location 3)
other are commented.(location1 & 2)
I got answer:

--------------------------------------------------------------------------------------------
Now Question:- I try to understand why i got 2 different values when i place different location with & without look & feel.

I know about
1. wait for reply.
2. People are investing their valuable time for me.
3. Study first & ask.
4. Try to google first.
5. Question should be Small simple.
6. & many more....things regarding getting answer.

Sorry for if my wrong view/thoughts.
Question remain to ask that what is wrong in my code so i got 2 different values in 2 different ways?

2.
Also i ask another question sizeof for swing?
no one answer...my question wrong or some thing else...
if answer is 'wait for more time' then i will be wait no issues...


Millions saw the apple fall, but Newton asked why.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I'm going to be honest with you, because hopefully it will help you out. Please take this as constructive criticism and try not to be insulted.

First, your questions are far too long and too complicated. Very few people are going to read a question spread over three screens of text. Don't give so much unnecessary background. The shorter and clearer a question is, the easier it is to answer. As an example, for the first question above, you might have just asked "Why do the sizes of my components change when I specify a look-and-feel?"

Second, your "questions" are actually each many questions. It's hard to even count precisely how many things you're asking above, or in the question you linked to. Try asking just one, focused question, and then you can ask follow-on questions in your replies.

Third, your questions are full of ideas that are just... wrong. To answer your questions, somebody would first have to tell you why they're wrong. Instead of asking ten questions, nine of which are based on guesses and speculations, ask one question, and try to read and understand and think about the answer before moving on to the next thing.

I hope this helps you. Good luck in the future.


[Jess in Action][AskingGoodQuestions]
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

Thanks Ernest Friedman-Hill & Bear Bibeault.
Don't give so much unnecessary background.

My question is how people understand i take effort & study before ask question...
i always get 1 quote from my teachers that once upon time America's president tells scientist only 1 line "Man should on moon as early as possible." & scientist work hard & make it possible.
But as programmer view customer requirement comes very short only one line.

"Why do the sizes of my components change when I specify a look-and-feel?"

Yes actually i want to ask same.

Third, your questions are full of ideas that are just... wrong. To answer your questions, somebody would first have to tell you why they're wrong.

I dont know They are "wrong" or my code is "wrong" or output is accurate! lots of confusion.

Instead of asking ten questions, nine of which are based on guesses and speculations, ask one question, and try to read and understand and think about the answer before moving on to the next thing.

This is helpful for me...i will think on it..& try to implement it.
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Mandar,

I think you completely missed the point put forward by Ernest Friedman-Hill. From your post, I understand that you have read HowToAskQuestionsOnJavaRanch. But you weren't able to apply it to your post. I would recommend that you read How To Ask Questions The Smart Way by Eric Steven Raymond.

You have not got reply to your another query as well. Now, it is the time to think what lacked that you didn't get reply. Try to follow above two links and try to modify your question.



Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Now Question:- I try to understand why i got 2 different values when i place different location with & without look & feel.

why do you need to know?
what problem does it create?

if there's no problem, and it's just a Julius Sumner Miller why-is-it-so?, you'll need to spend more time on google.

and the other topic you mentioned 'size of', has little/nothing directly to do with Swing.
the people most likely to answer questions about the inner workings of a PC
(heap/delta/memory-leaks etc) would be in another forum.
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

Thanks Palak Mathur & Michael Dunn,
How To Ask Questions The Smart Way by Eric Steven Raymond is really helpful.
I need to think about why i cant apply it when i ask question.


why do you need to know?
what problem does it create?

Currently it look like, it does not create problem, but may i say that we can not refuse that it may happen in future that it create big problem?

I think all my efforts to make question related to java swing is no useful. People not willing to read more than few lines. No answer to question which feels real tricky for questioner. Always give answer that contain how to ask questions the smart way.
I try to google...but i am questioner(who is not follow smart way) so i will not write about it.

I think all discussion goes under 'Psychology'...not 'java'.

When i ask question in ranch office, i waited 4 days before ask.
How can people tell me answer without
1. scenario about question.
2. how question arises.
3. steps for recreate/reproduce problem.

Here i ask question ( i think smarter way which shown by answerer/s).
But i thought,surely i will got answer which contain more ways to how to ask smart question or need to google(no one think after more than 400 question posted by questioner so...) or need to study first(no one tell what to study) or show some efforts(which no one want to see/read).
Sorry if my writing feels like i am not satisfy with all answers or something else.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Currently it look like, it does not create problem, but may i say that we can not refuse that it may happen in future that it create big problem?

I, for one, don't have a crystal ball, so all we can go on is the documentation, and if there's any warning/s.
quite often, you'll put a panel in a frame, give it a preferredSize, then if you check what size the panel is
after visible, it'll not be what you set, because the layoutManger tries a best-fit and that might be out by 4 or so,
probably because of a border (or something else) of another component.

> People not willing to read more than few lines.

in your opening post I read to line 6:
"Then i use open source look & feel.jtattoo"

never used it, not likely to, and I don't recall any other posts relating to that L&F, so, for me, no point reading any further.
you're probably better off trying to find a forum or mailing list which relates directly to that L&F.
You might get an answer here, but the source is the better place.

Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

Thanks Michael Dunn,
in your opening post I read to line 6:
"Then i use open source look & feel.jtattoo"

There 3 cases i use for java's default look & feel (MetalLookAndFeel)
Case 1, 2, & 3
& there are 3 cases for other open source look & feel
case 4, 5, & 6.
So for those cases where other open source look & feel used can be neglect because

you're probably better off trying to find a forum or mailing list which relates directly to that L&F.


Now question remain for only first 3 cases.

quite often, you'll put a panel in a frame, give it a preferredSize, then if you check what size the panel is
after visible, it'll not be what you set, because the layoutManger tries a best-fit and that might be out by 4 or so,
probably because of a border (or something else) of another component.

But Is there compulsory for use set all type of settings related to size when we want to no effect on values when visibility code from different location(frame.setVisible(true);)?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> But Is there compulsory for use set all type of settings related to size when we want to no effect on values when visibility code from different location(frame.setVisible(true);)?

I know it's just a language problem, but I don't understand the above, so I'll try to guess (on the size and visibility parts)

1) all your print statements have nothing to do with size, they just print the location of the component,
and most of the 0,0 ones are correct, regardless of the visibility aspect.

2) the location of the panels at 3,26 would be correct due to the tabbedPane's border(3) and the height of the 'tabs' (26)

3) why some of 2) show 0,0 then 3,26 is all to do with when the frame is visible
the #1 thing you need to understand is that until components are 'realized' (java term), they have no size and thay have no location.
being 'realized' generally means made visible, can also be if 'packed' e.g. frame.pack()
so, in your 3 cases:

case 1/location 1:
the print statements are printed when this line is executed
abcd window = new abcd();//abcd constructor calls initialize(), which prints the statements
'then' the window becomes visible
abcd window = new abcd();
window.frame.setVisible(true); //<-----------------

case 2/location 2:
this is a little harder to explain, because the tabbedPane shouldn't appear (I'll try to work out why, later)
in location 2, the frame is made visible, then, after the frame is visible the components are added to it,
meaning the components are not yet visible (at the time the print statements are executed)
add this line, which makes the frame re-layout it's components, you'll see the panel's bounds printed as per case 3/location 3


case 3/location3:
this is the correct location of frame.setVisible(true) for your example.
nothing wrong with location 1, but the print statements would need to be after
window.frame.setVisible(true);
but then they would have a 'scope' issue of no reference to the components.
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

Thanks Michael Dunn,
Your explanation is really helpful.
all your print statements have nothing to do with size,...


AsOracle's java doc about validate()
The validate method is used to cause a container to lay out its subcomponents again. It should be invoked when this container's subcomponents are modified (added to or removed from the container, or layout-related information changed) after the container has been displayed.


For cross verified above explanation & your explanation, i just add 1 nested Jtabbedpane with 2 jpanel in previous code & check...

when i use following code in public static void main,

i got result when i check following cases
case 1: location1 active(location 2,3 commented) & validate also.
case 2: Location 2 active (location 1,3 commented) & validate also. It look like Accurate.
case 3: Location 3 active (location 2,3 commented) & validate also. It also look like Accurate.

But when frame.validate(); is commented.
i got different values about size(width & height), you can see in [url=http://www.coderanch.com/t/588692/GUI/java/cointainer-components-size-diamentions]
cointainer/components size & diamentions![/url] last post written by me.

But i can guess as java's default 5 look & feel give me values as per required, when i follow to write
surely it also give proper values.
I also think that as java always give "the height of the 'tabs' (26)", might be that open source Jtatto gives "the height of the 'tabs' (31)"

Also i think difference between Frame size & its getlayeredpane size is use for frames upper portion where we can set icon, caption & minimize,close buttons are there. Is it true?
 
jQuery in Action, 2nd edition
 
subject: help needed for swing questions.
 
Similar Threads
JProgressBar in Napkin look and feel is not working
Why aren't my components wrapping?
How to add two buttons in each row?
cointainer/components size & diamentions!
Focus: cant find the relevant method