MultiScrollable.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package org.leumasjaffe.graphics;
  2. import java.awt.Component;
  3. import java.awt.GridBagConstraints;
  4. import java.awt.GridBagLayout;
  5. import javax.swing.JPanel;
  6. import javax.swing.JScrollPane;
  7. @SuppressWarnings("serial")
  8. public class MultiScrollable extends JPanel {
  9. public MultiScrollable(Component...components) {
  10. GridBagLayout layout = new GridBagLayout();
  11. layout.columnWidths = new int[]{0, 0};
  12. layout.rowHeights = prepareInts(components.length);
  13. layout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
  14. layout.rowWeights = prepareDoubles(components.length);
  15. setLayout(layout);
  16. for (int i = 0; i < components.length; ++i) {
  17. GridBagConstraints gbc_panel = new GridBagConstraints();
  18. gbc_panel.fill = GridBagConstraints.BOTH;
  19. gbc_panel.gridx = 0;
  20. gbc_panel.gridy = i;
  21. add(new JScrollPane(components[i]), gbc_panel);
  22. }
  23. }
  24. private double[] prepareDoubles(int length) {
  25. double[] dbls = new double[length+1];
  26. for (int i = 0; i < length; ++i) {
  27. dbls[i] = 1.0;
  28. }
  29. dbls[length] = Double.MIN_VALUE;
  30. return dbls;
  31. }
  32. private int[] prepareInts(int length) {
  33. int[] ints = new int[length+1];
  34. for (int i = 0; i < length+1; ++i) {
  35. ints[i] = 0;
  36. }
  37. return ints;
  38. }
  39. }