biskuteri-cafe-JKomasto2/PreviewComponent.java

59 lines
1.3 KiB
Java
Raw Normal View History

2021-07-16 00:37:03 +02:00
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.Box;
import java.awt.BorderLayout;
import java.awt.Font;
class
PreviewComponent extends JComponent {
private JLabel
topLeft, topRight, bottom;
// ---%-@-%---
public void
setTopLeft(String text) { topLeft.setText(text); }
public void
setTopRight(String text) { topRight.setText(text); }
public void
setBottom(String text) { bottom.setText(text); }
// ---%-@-%---
public
PreviewComponent()
{
Font font;
topLeft = new JLabel("Top left");
font = topLeft.getFont();
topLeft.setFont(font.deriveFont(Font.PLAIN, 12f));
setOpaque(false);
topRight = new JLabel("Top right");
topRight.setHorizontalAlignment(JLabel.RIGHT);
font = topRight.getFont();
topRight.setFont(font.deriveFont(Font.ITALIC, 12f));
setOpaque(false);
bottom = new JLabel("Bottom");
font = bottom.getFont();
bottom.setFont(font.deriveFont(Font.PLAIN, 16f));
bottom.setOpaque(false);
Box top = Box.createHorizontalBox();
top.add(topLeft);
top.add(Box.createGlue());
top.add(topRight);
setLayout(new BorderLayout());
add(top, BorderLayout.NORTH);
add(bottom, BorderLayout.SOUTH);
}
}