动态定制基因jFrame

时间:2014-10-17 10:17:18

标签: java swing

如何自定义jFrame并在其中设置jLabel的字体大小?

    final JFrame frame = new JFrame("Bill");
    frame.setLayout(new GridLayout(0, 1));
    try {
        String sql = "SELECT * FROM order_detail";
        rs = st.executeQuery(sql);
        while (rs.next()) {
            String printLbl = rs.getString("Prasada_Name") + "                      X                                     " + rs.getInt("Quantity") + "             " + rs.getInt("Prasada_Cost");
            frame.add(new JLabel(printLbl));
            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 > 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) {

        }
    }
    frame.setVisible(false);

我创建了新的jFrame并使用jLabel在其中添加了帐单,现在我想自定义它。怎么做?

1 个答案:

答案 0 :(得分:0)

  

如何自定义jFrame并为其设置jLabel的字体大小?

您可以使用setFont

JLabel jlabel = new JLabel("TEXT");
jlabel.setFont(new Font(jlabel.getFont(), Font.PLAIN, 12));