-2

I need to get the rectangle of a single column in the Table Header. Is there a way to receive this information?

Mureinik
  • 297,002
  • 52
  • 306
  • 350
dbausnnd
  • 59
  • 1
  • 3

1 Answers1

1

i hope you want to know the size of a cell from a table header?

to get the height of the the cell you must ask the tableheader for size and take its height

JTable table;
int height = table.getTableHeader().getSize().height //JTable header is a JComponent

to get the width of a cell you have to take the width from the tableColumnModel

int column; //the index of desired column
int width = table.getTableColumnModel().getColumn(column).getWidth(); //as mentioned by @MadProgrammer

as desired i add the hints on how to get the location

int xRel = table.getTableHeader().getX();
int column; //the index of desired column
for (int c = 0; c < column; c++){
    //adding all cell withds to come to your column
    x = x + table.getTableColumnModel().getColumn(c).getWidth();
} 

int yRel = table.getTableHeader().getY();

to get to the absolut coordinates you have to ask your frame, where it is and then add the relative coordinates

JFrame frame; //your frame
int xAbs = frame.getLocation().x + xRel;
int yAbs = frame.getLocation().y + yRel;
Martin Frank
  • 3,445
  • 1
  • 27
  • 47