jtable to image conversion not happening properly

后端 未结 3 1733
我寻月下人不归
我寻月下人不归 2021-01-15 13:05

I am trying to create a buffered image from a table, when i add the table to a application frame and set the size I am able to view it properly but when I convert it into an

3条回答
  •  深忆病人
    2021-01-15 13:41

    There are a few issues I can see here.

    • You should use printAll rather than paint when drawing to the image.

    • The height of the table is set when the pack method is called, but this is before the table is populated. If you are creating the image immediately after generating the table then the size may not be set. You should populate the table before you pack the frame - that should ensure the size is available when you need it.

    EDIT: Following your code change I would suggest removing the scroll pane (as kleopatra suggested) and then using printAll. paint should not be used for images as it can use double buffering. To see the header you will need to set its size using the code provided by kleopatra. The header's size is independent of the table so calling setSize on the table does not alter the header.

提交回复
热议问题