MessageFormat header = null;
if (this.headerBox.isSelected())
{
header = new MessageFormat(gradesLabel.toString());
}
MessageFormat footer = null;
if (this.footerBox.isSelected())
{
footer = new MessageFormat(this.footerField.getText());
}
boolean fitWidth = this.fitWidthBox.isSelected();
boolean showPrintDialog = this.showPrintDialogBox.isSelected();
boolean interactive = this.interactiveBox.isSelected();
JTable.PrintMode mode = fitWidth ? JTable.PrintMode.FIT_WIDTH :
JTable.PrintMode.NORMAL;
try
{
boolean complete = this.gradesTable.print(mode, header, footer,
showPrintDialog, null,
interactive, null);
if (complete)
{
JOptionPane.showMessageDialog(this,
"Printing Complete",
"Printing Result",
1);
}
else
JOptionPane.showMessageDialog(this,
"Printing Cancelled",
"Printing Result",
1);
}
catch (PrinterException pe)
{
JOptionPane.showMessageDialog(this,
"Printing Failed: " + pe.getMessage(),
"Printing Result",
0);
}
사실 Jtable 설명 개체를 전달하는 데 사용됩니다 인쇄() menthod, 하나 개 방법이있다 머리말과 꼬리말은 인쇄 할 매개 변수로 여기 headerBox는 내 프로그램 에서 만든 Jcheckbox이며 일부 Jlabels도 있습니다. 필요 없다면이 코드에서 해당 코드를 제거하고 프로그램을 실행하십시오.
지침에 따르면 '_'대신 camelCase를 사용해야합니다 : tableModel 및 columnNames. http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html을 참조하십시오. – Fortega