mirror of
https://gitlab.com/biskuteri-cafe/JKomasto2.git
synced 2024-11-20 06:04:51 +01:00
cda0891525
Used GridBagLayout for the first time..!
151 lines
3.3 KiB
Java
151 lines
3.3 KiB
Java
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JComponent;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.Box;
|
|
import javax.swing.BorderFactory;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.Font;
|
|
import java.awt.Dimension;
|
|
import java.awt.Insets;
|
|
import java.util.List;
|
|
import java.util.ArrayList;
|
|
|
|
class
|
|
TimelineWindow extends JFrame {
|
|
|
|
private Timeline
|
|
timeline;
|
|
|
|
// - -%- -
|
|
|
|
private TimelineComponent
|
|
display;
|
|
|
|
// ---%-@-%---
|
|
|
|
TimelineWindow()
|
|
{
|
|
getContentPane().setPreferredSize(new Dimension(300, 400));
|
|
pack();
|
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
|
|
setContentPane(display = new TimelineComponent());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class
|
|
TimelineComponent extends JPanel {
|
|
|
|
private JButton
|
|
next, prev;
|
|
|
|
private JLabel
|
|
pageLabel;
|
|
|
|
private final List<PreviewComponent>
|
|
previews = new ArrayList<>();
|
|
|
|
// ---%-@-%---
|
|
|
|
TimelineComponent()
|
|
{
|
|
prev = new JButton("<");
|
|
next = new JButton(">");
|
|
|
|
pageLabel = new JLabel("0 / 0");
|
|
|
|
Box bottom = Box.createHorizontalBox();
|
|
bottom.add(Box.createGlue());
|
|
bottom.add(prev);
|
|
bottom.add(Box.createHorizontalStrut(8));
|
|
bottom.add(pageLabel);
|
|
bottom.add(Box.createHorizontalStrut(8));
|
|
bottom.add(next);
|
|
|
|
JPanel centre = new JPanel();
|
|
centre.setOpaque(false);
|
|
centre.setLayout(new GridBagLayout());
|
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
|
constraints.gridx = 0;
|
|
constraints.weightx = 1;
|
|
constraints.insets = new Insets(4, 0, 4, 0);
|
|
for (int n = 8; n > 0; --n)
|
|
{
|
|
PreviewComponent preview = new PreviewComponent();
|
|
centre.add(preview, constraints);
|
|
previews.add(preview);
|
|
}
|
|
|
|
setLayout(new BorderLayout());
|
|
add(centre, BorderLayout.CENTER);
|
|
add(bottom, BorderLayout.SOUTH);
|
|
|
|
setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
}
|