Advertisement
billalmess

Scrollpane

Feb 10th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. /**
  2. * Initializes the scrollpane on which the spreadsheet is placed.
  3. * @return the scrollpane.
  4. */
  5.  
  6. public JScrollPane getJScrollPane()
  7. {
  8. if (jScrollPane == null)
  9. {
  10. jScrollPane = new JScrollPane();
  11. jScrollPane.addComponentListener(new java.awt.event.
  12. ComponentAdapter()
  13. {
  14. public void componentResized(
  15. java.awt.event.ComponentEvent e)
  16. {
  17. repainttable();
  18. if (getSelectedColumnCount() == 0 &&
  19. getSelectedRowCount() == 0)
  20. {
  21. if ((getColumnCount() > 1) && (getRowCount() > 1))
  22. {
  23. setColumnSelectionInterval(0, 0);
  24. setRowSelectionInterval(0, 0);
  25. }
  26. }
  27. }
  28. });
  29. jScrollPane.getHorizontalScrollBar().addAdjustmentListener(
  30. new SSScrollAdjListener(this));
  31. jScrollPane.getVerticalScrollBar().addAdjustmentListener(new
  32. SSScrollAdjListener(this));
  33. jScrollPane.setRowHeaderView(getViewPort());
  34. jScrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER,
  35. getRowHeader().getTableHeader());
  36. jScrollPane.setViewportView(this);
  37. }
  38.  
  39. return jScrollPane;
  40. }
  41.  
  42.  
  43. /**
  44. * Routine for AdjustmentListener of ScrollPane which is used for
  45. * supporting isCellVisible mode
  46. * @param isVerticalScrollbar VerticalScrollBar involved set true
  47. * or HorizontalScrollBar invloved set false
  48. */
  49.  
  50. public void scrollpaneRoutine(boolean isVerticalScrollbar)
  51. {
  52. if (isCellVisible)
  53. {
  54. if (isVerticalScrollbar)
  55. {
  56. int dif = jScrollPane.getVerticalScrollBar().getMaximum() -
  57. jScrollPane.getVerticalScrollBar().getValue() -
  58. jScrollPane.getVerticalScrollBar().getHeight();
  59. if (dif == 0)
  60. {
  61. this.addRow();
  62. }
  63. else if (Vindex > jScrollPane.getVerticalScrollBar().getValue())
  64. {
  65. int i = rowAtPoint(SwingUtilities.convertPoint(jScrollPane,
  66. 100, jScrollPane.getHeight(), this));
  67. int lastrow = 0;
  68. int[] rows = getSelectedRows();
  69. lastrow = (rows.length > 0) ? rows[rows.length - 1] :
  70. lastrow;
  71. i = (i < lastrow) ? lastrow : i;
  72. if (i > 0)
  73. {
  74. while (getRowCount() > i + 1)
  75. {
  76. if (checkRowDataExist(getRowCount() - 1) == false)
  77. {
  78. model.removeRow(this, getRowCount() - 1);
  79. }
  80. else
  81. {
  82. break;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. else
  89. {
  90. int dif = jScrollPane.getHorizontalScrollBar().getMaximum() -
  91. jScrollPane.getHorizontalScrollBar().getValue() -
  92. jScrollPane.getHorizontalScrollBar().getWidth();
  93. if (dif == 0)
  94. {
  95. int c[] = getSelectedColumns();
  96. int r[] = getSelectedRows();
  97. addColumn();
  98. addSelectionInterval(r, c);
  99. getTableHeader().repaint();
  100. }
  101. else if (Hindex >
  102. jScrollPane.getHorizontalScrollBar().getValue())
  103. {
  104. int i = columnAtPoint(SwingUtilities.convertPoint(
  105. jScrollPane,
  106. jScrollPane.getWidth(), 50, this));
  107. int lastcol = 0;
  108. int[] cols = getSelectedColumns();
  109. lastcol = (cols.length > 0) ? cols[cols.length - 1] :
  110. lastcol;
  111. i = (i < lastcol) ? lastcol : i;
  112. if (i > 0)
  113. {
  114. while (getColumnCount() > i + 1)
  115. {
  116. if (checkColumnDataExist(getColumnCount() - 1) ==
  117. false)
  118. {
  119. model.removeColumn(this, getColumnCount() - 1);
  120. }
  121. else
  122. {
  123. break;
  124. }
  125. }
  126. }
  127. }
  128. }
  129. Hindex = jScrollPane.getHorizontalScrollBar().getValue();
  130. Vindex = jScrollPane.getVerticalScrollBar().getValue();
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement