如何自定义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
在其中添加了帐单,现在我想自定义它。怎么做?
答案 0 :(得分:0)
如何自定义jFrame并为其设置jLabel的字体大小?
您可以使用setFont
JLabel jlabel = new JLabel("TEXT");
jlabel.setFont(new Font(jlabel.getFont(), Font.PLAIN, 12));