9 Replies - 5570 Views - Last Post: 06 July 2010 - 07:41 PM Rate Topic: -----

#1 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Setting JTable Column Widths

Posted 02 July 2010 - 08:48 PM

Is there a way to set the column width in a JTable? I noticed there was a setRowHeight method but not a method for setting the width...I also looked at TableColumnModels but it didn't have a width setting method either...
Is This A Good Question/Topic? -2
  • +

Replies To: Setting JTable Column Widths

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Setting JTable Column Widths

Posted 02 July 2010 - 08:51 PM

When you have little problems like this, you would problably find it quicker to google something like JTable set column width. First result which came up
int rows = 3;
int cols = 3;
JTable table = new JTable(rows, cols);

// Disable auto resizing
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

// Set the first visible column to 100 pixels wide
int vColIndex = 0;
TableColumn col = table.getColumnModel().getColumn(vColIndex);
int width = 100;
col.setPreferredWidth(width);

This post has been edited by nick2price: 02 July 2010 - 08:52 PM

Was This Post Helpful? 1
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Setting JTable Column Widths

Posted 02 July 2010 - 09:01 PM

// Disable auto resizing
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

// set the default width to 100 pixels for col 0
TableColumn col = table.getColumnModel().getColumn(0);
col.setPreferredWidth(100);



But I am sure that

Google jtable column width

would have give you a lot of example about it
Please Google before posting here

beaten by nick2price :^: who came to the same conclusion than me

Please Google first

This post has been edited by pbl: 02 July 2010 - 08:59 PM

Was This Post Helpful? 1
  • +
  • -

#4 LynnL  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 109
  • Joined: 13-April 09

Re: Setting JTable Column Widths

Posted 02 July 2010 - 09:40 PM

Yes as PBL said Google first
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Setting JTable Column Widths

Posted 02 July 2010 - 10:04 PM

-1 for giving a -1 to LynL comment about the fact that you should Google first... she is right
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Setting JTable Column Widths

Posted 02 July 2010 - 10:34 PM

Unfortunately I gave a minus rep for trying to send members back to Google. Y'all need to know that a large amount of the members we have here come from s Google Link, and the only think they see when they get here is someone telling them to go back to Google.

Guys we're here to help developers & programmer alike. If all they ever get when they reach us o Dream.In.Code is a bunch of people sending them back to Google what kind of reputation do you think we're going to have in the end run?

They came here from Google, or Bing, or some other searchengine so let's treat them the wan they deserve. Just My 2
Was This Post Helpful? 1
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Setting JTable Column Widths

Posted 03 July 2010 - 07:47 PM

View PostPsychoCoder, on 02 July 2010 - 11:34 PM, said:

Unfortunately I gave a minus rep for trying to send members back to Google. Y'all need to know that a large amount of the members we have here come from s Google Link, and the only think they see when they get here is someone telling them to go back to Google.

Guys we're here to help developers & programmer alike. If all they ever get when they reach us o Dream.In.Code is a bunch of people sending them back to Google what kind of reputation do you think we're going to have in the end run?

They came here from Google, or Bing, or some other searchengine so let's treat them the wan they deserve. Just My 2

According to the forum rules

Utilize the "Search" feature. Many questions have already been asked and answered in another thread.

The only problem is that GUI has a poor search engine, you cannot, or at least you could not, search for more than one single word... but at least Google could point you to a DIC topic with the answer

We also want to see, according to the rules, a minimum of effort... post the code you have done and we will help you if you have problem with it

Do you consider that:

Quote

Is there a way to set the column width in a JTable? I noticed there was a setRowHeight method but not a method for setting the width...I also looked at TableColumnModels but it didn't have a width setting method either...

represent a minimum of effort ? Where is the code that we can fix ?
Was This Post Helpful? 1
  • +
  • -

#8 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,258
  • Joined: 27-December 08

Re: Setting JTable Column Widths

Posted 03 July 2010 - 07:52 PM

At the very least, we can at least direct the OP to the API for a specific class.

For questions like "where do I download NetBeans?" I agree with you. For questions like this where the OP is looking for a tool after being stonewalled by research, I don't have a problem linking to an API.
Was This Post Helpful? 1
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Setting JTable Column Widths

Posted 06 July 2010 - 03:53 PM

View PostPsychoCoder, on 02 July 2010 - 11:34 PM, said:

Unfortunately I gave a minus rep for trying to send members back to Google. Y'all need to know that a large amount of the members we have here come from s Google Link, and the only think they see when they get here is someone telling them to go back to Google.

Guys we're here to help developers & programmer alike. If all they ever get when they reach us o Dream.In.Code is a bunch of people sending them back to Google what kind of reputation do you think we're going to have in the end run?

They came here from Google, or Bing, or some other searchengine so let's treat them the wan they deserve. Just My 2


JackOfAllTrades seems to agree with me

http://www.dreaminco...gopid__1059074&
Was This Post Helpful? 0
  • +
  • -

#10 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: Setting JTable Column Widths

Posted 06 July 2010 - 07:41 PM

Additionally, I personally said to google first as this is the best way to help. It took me 5 seconds to retrieve that piece of code i posted, whereas posting on a forum, you may be waiting 10 minutes for a reply (Lucky its dreamincode, other forums I would be saying 2 hours!). Also, googling 'jtable width' does not provide any links on the first page to dreamincode. I know we hate to admit it, but being able to find and reuse code is a huge part of programming.

p.s. I am not ranting. I tottally agree that we should help fellow programmers out with their issues, just think that something like this does not need to ever be an issue for the op.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1