在同一页面打印两个jpanel和jablte

时间:2017-04-28 12:04:52

标签: java swing printing jpanel

关闭我的所有java GUI,我想在同一页面中打印两个jpanel。 然而,其中一个jpanels里面有一张桌子。 我正在使用的方法没有正确获取表。 任何想法,我怎么能得到,例如,图像中的确切格式?图像中的格式是我GUI的一部分副本。

Example of my output in my GUI i want to print exactly has it is

以下是我如何在h2数据库中填充gui中的信息:

 private void jList1MouseClicked(java.awt.event.MouseEvent evt) {                                    

    String str = jList1.getSelectedValue();

    System.out.println("testeselection" + str);
    int ID = Integer.parseInt(str.substring(str.indexOf("[") + 1, str.indexOf("]")));

    try {
        ResultSet rs = databaseManager.loadFromList(ID);
        ResultSet rs2 = databaseManager.loadTable(ID);
        while (rs.next()) {
            IDinterno.setText(rs.getString("IDinterno"));
            gRemessa_num.setText(rs.getString("gRemessa_num"));
            System.out.println("data" + rs.getString("data"));

            Calendar cal = Calendar.getInstance();
            cal.setTime(rs.getDate("data"));
            data.setSelectedDate(cal);

            nome_cliente.setText(rs.getString("nome_cliente"));
            partida_num.setText(rs.getString("partida_num"));
            quant.setText(rs.getString("quant"));
            nota.setText(rs.getString("nota"));

        }


        int i= 0;




                Object calObj ;




        while (rs2.next()) {
            System.out.println(rs2.getInt("ordemID") + rs2.getString("descricao")  + rs2.getDate("dataP"));

             calObj = rs2.getDate("dataP");
           /* try {
               /* Date dateLoad = sdf.parse(calObj.toString());
                 calendar.setTime(dateLoad);
                dateLoad = sdfFinal.parse(calObj.toString());
                calObj = dateLoad;


            } catch (ParseException ex) {
                Logger.getLogger(MainView.class.getName()).log(Level.SEVERE, null, ex);
            }*/



            jTable2.getModel().setValueAt(rs2.getString("descricao") ,i, 1);
            jTable2.getModel().setValueAt( calObj ,i, 2);


            i++;
        }

        /*  Object[] objects = new Object[colNo];
            for (int i = 0; i < colNo; i++) {
                objects[i] = rs.getObject(i + 1);
            }
            aModel.addRow(objects);



        }  
        jTable2.setModel(aModel);*/
    } catch (SQLException ex) {
        Logger.getLogger(MainView.class.getName()).log(Level.SEVERE, null, ex);
    } 


}    

这里有一个示例,我尝试使用与图像完全相同的打印方式,但格式不正确。

    private void printBtnActionPerformed(java.awt.event.ActionEvent evt) {                                         


        PrinterJob pj = PrinterJob.getPrinterJob();
  pj.setJobName(" Print Component ");

  pj.setPrintable (new Printable() {    
    public int print(Graphics pg, PageFormat pf, int pageNum){
      if (pageNum > 0){
      return Printable.NO_SUCH_PAGE;
      }

      Graphics2D g2 = (Graphics2D) pg;
      g2.translate(pf.getImageableX(), pf.getImageableY());
      PanelMain.paint(g2);
      jPanel2.paint(g2);
      return Printable.PAGE_EXISTS;
    }

0 个答案:

没有答案