From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing3801.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3801.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3801.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3801.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3801.java new file mode 100644 index 0000000..8a78326 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3801.java @@ -0,0 +1,73 @@ +/* Listing3801.java */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +public class Listing3801 +extends JFrame +{ + public Listing3801() + { + super("JScrollPane"); + addWindowListener(new WindowClosingAdapter(true)); + //Dialogpanel erzeugen + JPanel panel = new JPanel(); + panel.setLayout(new GridLayout(10, 10)); + for (int i = 1; i <= 100; ++i) { + panel.add(new JCheckBox("Frage " + i)); + } + //JScrollPane erzeugen + JScrollPane scroll = new JScrollPane(panel); + scroll.setCorner( + JScrollPane.UPPER_RIGHT_CORNER, + new JLabel("1", JLabel.CENTER) + ); + scroll.setCorner( + JScrollPane.LOWER_RIGHT_CORNER, + new JLabel("2", JLabel.CENTER) + ); + scroll.setColumnHeaderView(new ColumnHeader(panel, 10)); + //JScrollPane zur ContentPane hinzufügen + getContentPane().add(scroll, BorderLayout.CENTER); + } + + public static void main(String[] args) + { + Listing3801 frame = new Listing3801(); + frame.setLocation(100, 100); + frame.setSize(300, 150); + frame.setVisible(true); + } +} + +class ColumnHeader +extends JComponent +{ + JComponent component; + int columns; + + public ColumnHeader(JComponent component, int columns) + { + this.component = component; + this.columns = columns; + } + + public void paintComponent(Graphics g) + { + int width = component.getSize().width; + int height = getSize().height; + int colwid = width / columns; + for (int i = 0; i < columns; ++i) { + g.setColor(i % 2 == 0 ? Color.yellow : Color.gray); + g.fillRect(i * colwid, 0, colwid, height); + } + g.setColor(Color.black); + g.drawLine(0, height - 1, width, height - 1); + } + + public Dimension getPreferredSize() + { + return new Dimension(component.getSize().width, 20); + } +} \ No newline at end of file -- cgit v1.2.3