| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package org.leumasjaffe.graphics;
- import java.awt.Component;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- @SuppressWarnings("serial")
- public class MultiScrollable extends JPanel {
- public MultiScrollable(Component...components) {
- GridBagLayout layout = new GridBagLayout();
- layout.columnWidths = new int[]{0, 0};
- layout.rowHeights = prepareInts(components.length);
- layout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
- layout.rowWeights = prepareDoubles(components.length);
- setLayout(layout);
- for (int i = 0; i < components.length; ++i) {
- GridBagConstraints gbc_panel = new GridBagConstraints();
- gbc_panel.fill = GridBagConstraints.BOTH;
- gbc_panel.gridx = 0;
- gbc_panel.gridy = i;
- add(new JScrollPane(components[i]), gbc_panel);
- }
- }
- private double[] prepareDoubles(int length) {
- double[] dbls = new double[length+1];
- for (int i = 0; i < length; ++i) {
- dbls[i] = 1.0;
- }
- dbls[length] = Double.MIN_VALUE;
- return dbls;
- }
- private int[] prepareInts(int length) {
- int[] ints = new int[length+1];
- for (int i = 0; i < length+1; ++i) {
- ints[i] = 0;
- }
- return ints;
- }
- }
|