Another JTable question

I am trying to resize the widths of the columns in a JTable.

At present two of my column headings do not fit and the names trail off with ...
I would need to resize them when the program is running to see the full column header names - this is not really desirable

I have tried creating a header

JTableHeader header = table.getTableHeader();

and then typed

header.

(and let Eclipse give me a list of availble commands associated with table headers but I dont see anything that is gonna do it for me)

I have also tried

table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS)

But that just seems to ensure that if my table is wider than the frame it is contained in then I have a horizontal scrollbar to scroll to the columns that are off screen

How can I make the columns as wide as they need to be to display all the text?

Also, having done that I would like it if the user could not resize the columns themselves when the program is running.

Don't use Eclipse's auto complete as a substitute for documentation and research. For example, did you read this?

Don't use Eclipse's auto complete as a substitute for documentation and research. For example, did you read this?

Yes I did read it and it was a complete waste of time. Its all very well creating a two dimensional array for a table if you are going to state the arrays values in the code - I mean who really does that.

The examples are way to basic to aid someone who wants to search through a linked list, and where a record is found that matches certain criteria as specified by a user , copy those records into a two dimensional array that is only the size it needs to be to hold those records (ie no empty elements which will result in empty rows in a table) and then create a JTable to display those records to the user.

I think I have done well to research JTables and also use my own inititive to piece together a solution to my problem. All I want to do is tidy up the interface to limit the end users ability to interact with the table.

If you dont want to contribute to a answer thats fine - I dont expect any answers but dont under any curcumstances insinuate that I have not RESEARCHED JTables and am just trying to get someone else to do the work for me!!!!

Relax. It was a question, not an accusation. Nice rant though, now I'm a lot more likely to help you.

commented: Yeah, no kidding. Warm fuzzies abound! +10

Yes I did read it and it was a complete waste of time. Its all very well creating a two dimensional array for a table if you are going to state the arrays values in the code - I mean who really does that.

The examples are way to basic to aid someone who wants to search through a linked list, and where a record is found that matches certain criteria as specified by a user , copy those records into a two dimensional array that is only the size it needs to be to hold those records (ie no empty elements which will result in empty rows in a table) and then create a JTable to display those records to the user.

The examples are meant to provide a foundation on various topics, not provide a complete guide of how to do everything. The JTable tutorials make no attempt to teach topics like LinkedLists and searching, since those topics have nothing to do with JTables. Anyway, I can understand your frustration, since some topics in Swing are definitely difficult to understand. The question I asked you earlier was mostly to determine what level of effort you put into finding the answer, especially since your question has been asked many times before. For example,

This example demonstrates how to adjust the width of a column to be just wide enough to show all of the column header and the widest cell in the column.

If you dont want to contribute to a answer thats fine - I dont expect any answers but dont under any curcumstances insinuate that I have not RESEARCHED JTables and am just trying to get someone else to do the work for me!!!!

Is it okay to insinuate that perhaps you didn't read this portion of what he linked quite thoroughly enough? Would the circumstance that it specifically addresses setting the column width warrant a pass on your admonition?

commented: eloquently said.. :) +5

Is it okay to insinuate that perhaps you didn't read this portion of what he linked quite thoroughly enough? Would the circumstance that it specifically addresses setting the column width warrant a pass on your admonition?

I read that particular document over a month ago when i first wanted to use a jtable and since it did not even help me get my data into the table, why would i go back to it for help in doing anything else with a jtable?

Yes, as it happens the document does explain resizing columns but what has that got to do with the manner in which he replied to my thread. You make it sound as if you can talk to people however you want to, if those people are asking for your help - well i don't think so!!!

Why could he not have said "if you want to resize a column i think this document will be of some help to you" rather than talk down to me in a patronising manner.

I really dont understand why either of you come on here and reply to questions if you can't talk to people with respect - i can only assume that you like to come on here because it makes you feel superiour, you certainly dont appear to genuinly want to help others, of is it just students you dont like?

I cannot believe that i asked a perfectly polite question and ended up having to defend myself.

I dont believe you even replied to be of help - you just replied to put me in my place!!!!

As a 37 year old women on a male dominated degree, and when i say male dominated i mean 18/19 year old "boy" dominated, i really am to old for this sort of crap from people!!!!!

So naturally i won't be back to ask anymore questions - i would rather fail my degree than bow down to people like you who only want to "nit pick".

Two people who have obviously used it before provided it as a resource that would help you solve your problem. That should be enough reason to take another look or at least apologize (or not whine) when you find out you're wrong. You're misusing the word patronizing. At the worst, a sane person would interpret my question as rhetorical and assuming. Your response shows how little you know about this site or the people on it. Almost everyone who asks a question in this forum is a student. I'm also a student myself. Age has nothing to do with learning or teaching, or being wrong or being right. Age in and of itself isn't a good or bad quality. Some people mistakenly associate age with both good and bad qualities, but age only allows a person time to attain good or bad qualities, it doesn't instill these qualities in someone.

> So naturally i won't be back to ask anymore questions - i would rather fail my degree than bow down to people like you who only want to "nit pick".

Great, we'll miss, err...nit picking you.

Edit: Cross-posted with the above.

goofy_chick,
I think you have some sensitivity issues personally. You over-read condescension into his reply and then blew up in an indignant rant, completely ignoring that his link did have the answer to your question. You also might consider that his original comment on documentation was directly related to your mention that you hadn't found what you needed in the auto-completion for the TableHeader.

I read that particular document over a month ago when i first wanted to use a jtable and since it did not even help me get my data into the table, why would i go back to it for help in doing anything else with a jtable?

Perhaps because you were looking for different information this time? Perhaps you didn't notice it earlier? There was a specific sub-section link for resizing columns.

I cannot believe that i asked a perfectly polite question and ended up having to defend myself.

I dont believe you even replied to be of help - you just replied to put me in my place!!!!

I replied to point out you ignored the fact that the information he linked did address your question and you decided to yell at him instead. I also linked directly to that sub-section in my reply. Your original question was indeed polite, but your response was far from it.

As a 37 year old women on a male dominated degree, and when i say male dominated i mean 18/19 year old "boy" dominated, i really am to old for this sort of crap from people!!!!!

As a 39 year old man working in the field, I can tell you that you're going to have a rough time if you are this thin-skinned about "this sort of crap from people" when they point you to relevant documentation and expect you to actually read it. You may not like it, but RTFM is the norm in this occupation.

So naturally i won't be back to ask anymore questions - i would rather fail my degree than bow down to people like you who only want to "nit pick".

I honestly don't care about you bowing down to anyone, but you really should thank BJSJC for offering even more detailed assistance after you blew up at him the first time when many others wouldn't have.

I also think you have too many exclamation points in your post.

[Disclaimer: I'm not a moderator of this particular board section. Java just happens to be the language I work in the most and this forum is where I have made the majority of my posts. All of this is just my opinion as a regular contributor here.]

I aswell as a professional pro can verify that the answer you are looking for is made very avaliable in the first post that was posted by "BestJewSinceJC". And I did not find his or anyones comments patronizing in any way. You would normaly hear infinitely more patronizing stuff coming out of programmers mouths. This was all love and candies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.