Printing a large Swing component

前端 未结 4 1757
栀梦
栀梦 2020-11-27 07:47

I have a Swing form with a custom table inside a JScrollPane (it\'s just a JPanel, not a JTable subclass), and I am trying to get it to print. If I just send the whole frame

4条回答
  •  囚心锁ツ
    2020-11-27 08:32

    you have to print the component without scrollpane. the scrollpane will always only prints the visible content.

    if you havent access to the createPanel() Method, and the panel from this method only contains the scrollpane, you can get the component, which the scrollpane contains, in the following way:

    JPanel panel = createPanel();
    print(((JScrollPane)panel.getComponents()[0]).getViewport());
    

    but if your data is format as a table, you can also about using the JTable. the JTable has a own powerful print() Method. more infos at http://download.oracle.com/javase/tutorial/uiswing/misc/printtable.html

提交回复
热议问题