Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

auto-resize JTable column width and print that table?

  Asked By: Harley    Date: Jul 28    Category: Java    Views: 1625
  

First, I have about 20 columns to display in one JTable. OK, all
columns displayed, but their width are so small. I thought there will
be a horizontal scrollbar (automatically I thought), but no
horizontal scrollbar displayed. Can anyone tell me how can I resize
all columns, depending on each column longest content??? I found no
such method (setColumnWidth(), or kind like that) in Java API.
I want to resize all columns automatically, so when I create Jtable,
there will be a horz scrollbar.

And how can I set all cells to become uneditable???

This is the last.... I try to apply Printable or Pageable interface
to print the table (public class SearchResult implements
Printable)....
I can display the print dialog, but when the paper printed, it's
blank.... Nothing printed..

This is my part of code to print...

public int print(Graphics g, PageFormat pf, int pi)
throws
PrinterException {
if (pi >= 1) {
return Printable.NO_SUCH_PAGE;
}
return Printable.PAGE_EXISTS;
}


public void actionPerformed(ActionEvent event) {
String action = event.getActionCommand();

if (action.equals(this.PRINT)) {
PrinterJob printJob = PrinterJob.getPrinterJob
();
printJob.setPrintable(this);
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception ex) {
ex.printStackTrace();
}
}

I've got this code from Java tutorial, but I don't know it's
meaning.. Please help me on these three problems, please.....

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on auto-resize JTable column width and print that table? Or get search suggestion and latest updates.




Tagged: