• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Centering JLabel when Spanning Columns Using GridBagLayout

 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a series of columns in my JDialog and I want to place a JLabel over a subset of them. I am using 'gridwidth=6' to span those columns (2-7). However the JLabel is centered in column 2 rather than centered over the spanned columns. I cannot find anything in the documentation that discusses centering over spanned columns. Can someone point me to the right place in the documentation? TIA.
 
Rob Camick
Ranch Hand
Posts: 2675
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seriously??? Why on earth can't you post a proper SSCCE that demonstrates the problem???

Until you actually take the time to answer questions in a forum, you have no idea what information we need to solve a problem. You have been asked numerous times to post a SSCCE be we need to see exactly what you are doing so we don't waste time guessing what mistakes you are making.

The code would be about 20 - 30 lines of code. A few lines to create the frame. A few lines to create and add 6 components to the frame. Another couple to add the label to the frame.

However the JLabel is centered in column 2 rather than centered over the spanned columns


The point of asking a question when something doesn't work is to produce the code showing that you have made an actual effort to solve the problem on your own.

Why would it be centered over column 2 instead of column1. It would seem that the problem is your code not the documentation.

A GridBagLayout is one of the most complicated layout managers to use. It is not a matter of using a single constraint. All the constraints work together to give you the desired effect.

There could be several problems in your code and we can't guess which constraints you might be using incorrectly.

When we see what you are doing, then we can't point you to the part of the documentation that you are misunderstanding.


 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seriously??? Why on earth can't you ever read my questions??? I'm not mis-understanding anything, yet. There is no SSCCE to post because I haven't written anything yet. I'm not even sure it is what I want to do. I'm looking for help finding documentation so I CAN write the code if I choose. Where in the documentation does it discuss centering in spanned columns rather than centering in a single column? Why is that so hard to understand?
 
Rob Camick
Ranch Hand
Posts: 2675
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  I haven't written anything yet.


You stated:

I want to place a JLabel over a subset of them. I am using 'gridwidth=6' to span those columns (2-7). However the JLabel is centered in column 2 rather than centered over the spanned columns


This implies you have tested code and it doesn't do what you want.

I cannot find anything in the documentation


What documentation? Are you talking about the API or a tutorial? We don't know what you are talking about, so we don't know if we can provide any addition links or help.

Once again you ask a question without complete information and we have to make assumptions about what you are talking about.

Where in the documentation does it discuss centering in spanned columns rather than centering in a single column? Why is that so hard to understand?


Why do you think it is different (single column vs spanned column)? Once again you continue to make false assumptions without even trying it. That is the whole point of a SSCCE. You read something and you try it. If it doesn't work the way you expect you post the code.

We are not here to interpret the documentation you read.

You first make an effort.
 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This implies you have tested code and it doesn't do what you want.

That is an (invalid) assumption on your part. I was referring to what the documentation states. Remember this is a documentation question. My apologies for not stating it suitably to you.
And I have lost track of the number of times I have referred you to the Swing tutorial.

I know I don't always make my questions clear but what part of "I cannot find anything in the documentation" is confusing you?
 
Rob Camick
Ranch Hand
Posts: 2675
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now you are being unreasonable. We can only answer questions based on the context of the question, not what you are thinking in your mind

what part of "I cannot find anything in the documentation" is confusing you?


We don't know what you are talking about.

"Documentation" to me means the API documentation for the GridBagLayout class.

"Swing tutorial" is where you should be looking for help on how to use the Swing classes. This is where I always tell you to look.

Maybe you are talking about something else? Maybe you are reading a book?

Unless you state the source of the documentation you can only make assumptions.

Whenever I ask a question I state the source and then quote the statement that is confusing me.


I have a series of columns in my JDialog and I want to place a JLabel over a subset of them. I am using 'gridwidth=6' to span those columns (2-7). However the JLabel is centered in column 2 rather than centered over the spanned columns


The above describes your requirement and seems to indicate you can't position the label the way you want.

You state you have set the gridwidth to 6. Well I searched the Swing tutorial on "How to Use GridBagLayout" and nowhere in the tutorial example does it set the value to 6, so this also implies that you have written some code and tried something that didn't work.


So once again, if you have a question, try it first, don't assume it doesn't work. If you try it and it doesn't work then post your SSCCE demonstrating the problem.


 
Dennis Putnam
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"Documentation" to me means the API documentation for the GridBagLayout class.

To me documentation means documentation from all sources. Glad we have that defined now so you will understand what I have looked for.

So once again, if you have a question, try it first, don't assume it doesn't work.

I guess I am unique in that I PLAN before I act.

Since we seem to be having so much difficulty communicating and we are obviously getting irritated with each other, perhaps you should leave answering my questions to others. If I've managed to alienate myself with "others" as well then I apologize and will seek help from other forums.
 
Rob Camick
Ranch Hand
Posts: 2675
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad we have that defined now so you will understand what I have looked for.


No, I won't understand what you have looked for. I am not a mind reader, I don't know what sources you have consulted.

That is why you need to explicitly state the source and text causing the confusion.

Same with code. Unless we see the code we don't know what is confusing you.

We are not mind readers!!!

I guess I am unique in that I PLAN before I act.


Exactly you come up with a potential solution and then you write simple code to test the solution to see if it works before applying the solution to a complex program.

This is the whole point of a SSCCE.

If it works great you go along with the solution, if not, you have simple code to post to see if others can help.

We are not here to spoon feed you the code if you don't try it first.

perhaps you should leave answering my questions to others


No the solution is simple. Listen to advice from people that have been answering questions for many years.

The forum is here when you have a problem.  We are glad to help when you show that you have made an effort to solve a problem.

It only takes 5 minutes to create your SSCCE and test your assumption.

I will continue to answer questions, just to let others who happen to read the question know what your past attitude has been like.

I do not appreciate it when someone takes advantage of our generosity and our time and does not make an effort.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic