title: Generating a receipt dynamically
body: <pre><code>     final JFrame frame = new JFrame("Bill");
      frame.getContentPane().setBackground(Color.WHITE);
       JLabel jlabel = new JLabel("");
          jlabel.setFont(new Font("Serif", Font.PLAIN, 12));
          frame.add(jlabel);
          frame.validate();
          frame.repaint();
          jlabel = new JLabel("-----------BILL-----------");
          jlabel.setFont(new Font("Serif", Font.PLAIN, 20));
          frame.add(jlabel);
          frame.validate();
          frame.repaint();
  
          jlabel = new JLabel("");
          jlabel.setFont(new Font("Serif", Font.PLAIN, 12));
          frame.add(jlabel);
          frame.validate();
          frame.repaint();
      frame.setLayout(new GridLayout(0, 3));
      try {
  
          String sql = "SELECT * FROM order_detail";
          rs = st.executeQuery(sql);
          frame.add(new JLabel("Item"));
              frame.validate();
              frame.repaint();
              frame.add(new JLabel("Quantity"));
              frame.validate();
              frame.repaint();
              frame.add(new JLabel("Amount"));
              frame.validate();
              frame.repaint();
          while (rs.next()) {
              String printLbl = rs.getString("Item");
              frame.add(new JLabel(printLbl));
              frame.validate();
              frame.repaint();
              printLbl =""+rs.getInt("Quantity");
              frame.add(new JLabel(printLbl));
              frame.validate();
              frame.repaint();
              printLbl = ""+rs.getInt("Cost");
              frame.add(new JLabel(printLbl));
              frame.validate();
              frame.repaint();
  
          }
          frame.add(new JLabel(""));            
          frame.validate();
          frame.repaint();
          frame.add(new JLabel("Total"));            
          frame.validate();
          frame.repaint();
          frame.add(new JLabel(jLabel82.getText()));            
          frame.validate();
          frame.repaint();
      } catch (SQLException e) {
          System.out.println(e.getMessage());
      }
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(700, 400);
      frame.setVisible(true);
      PrinterJob job = PrinterJob.getPrinterJob();
      job.setJobName("frame");
      job.setPrintable(new Printable() {
          public int print(Graphics pg, PageFormat pf, int pageNum) {
              if (pageNum &gt; 0) {
                  return Printable.NO_SUCH_PAGE;
              }
  
              Graphics2D g2 = (Graphics2D) pg;
              g2.translate(pf.getImageableX(), pf.getImageableY());
              frame.paint(g2);
              return Printable.PAGE_EXISTS;
          }
      });
      boolean ok = job.printDialog();
      if (ok) {
          try {
              job.print();
          } catch (PrinterException ex) {
  
          }
  </code></pre>
  
  <p>i want to create a bill receipt in which the  items are fetched from data base bill will generated. I have used the  above code for that but the problem i am facing is its format. How can I put it in a proper bill receipt format?</p>