Java Code Examples for javax.swing.JScrollPane#getVerticalScrollBar()

The following examples show how to use javax.swing.JScrollPane#getVerticalScrollBar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockableMenu.java    From rapidminer-studio with GNU Affero General Public License v3.0 7 votes vote down vote up
/**
 * Ensures that the correct maximum height is set for the popup menu and sets the scroll increment.
 * Will only take effect with the first item added. Makes sure the height is set to {@link #MAX_SHOWN_ITEMS}*itemHeight.
 *
 * @since 8.2
 */
private void ensurePopupHeight() {
	JPopupMenu popupMenu = getPopupMenu();
	if (popupMenu.getSubElements().length != 1 || !(popupMenu instanceof ScrollableJPopupMenu)) {
		return;
	}
	ScrollableJPopupMenu scrollablePopup = (ScrollableJPopupMenu) popupMenu;
	int itemHeight = scrollablePopup.getComponentsInsideScrollpane()[0].getPreferredSize().height;
	int maxHeight = MAX_SHOWN_ITEMS * itemHeight;
	maxHeight = Math.min(maxHeight, ScrollableJPopupMenu.SIZE_HUGE);
	scrollablePopup.setMaxHeight(maxHeight);
	JScrollPane scrollPane = scrollablePopup.getScrollPane();
	JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
	verticalScrollBar.setUnitIncrement(itemHeight);
	verticalScrollBar.setBlockIncrement(maxHeight);
}
 
Example 2
Source File: Outline.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
      public void componentMoved(ComponentEvent e) {
   if(timer == null) {
JScrollPane   scrollPane = getScrollPane();

if(scrollPane == null) {
    change();
              } else {
    scrollBar = scrollPane.getVerticalScrollBar();
    if(scrollBar == null || 
	!scrollBar.getValueIsAdjusting()) {
	// Try the horizontal scrollbar.
	if((scrollBar = scrollPane.getHorizontalScrollBar())
	    != null && scrollBar.getValueIsAdjusting()) {
                              
	    startTimer();
                      } else {
	    change();
                      }
    } else {
	startTimer();
                  }
}
   }
      }
 
Example 3
Source File: MBasicTable.java    From javamelody with Apache License 2.0 6 votes vote down vote up
@Override
protected void configureEnclosingScrollPane() {
	// Si cette table est la viewportView d'un JScrollPane (la situation habituelle),
	// configure ce ScrollPane en positionnant la barre verticale à "always"
	// (et en installant le tableHeader comme columnHeaderView).
	super.configureEnclosingScrollPane();

	final Container parent = getParent();
	if (parent instanceof JViewport && parent.getParent() instanceof JScrollPane) {
		final JScrollPane scrollPane = (JScrollPane) parent.getParent();
		if (scrollPane.getVerticalScrollBar() != null) {
			scrollPane.getVerticalScrollBar().setFocusable(false);
		}
		if (scrollPane.getHorizontalScrollBar() != null) {
			scrollPane.getHorizontalScrollBar().setFocusable(false);
		}

		final JViewport viewport = scrollPane.getViewport();
		if (viewport == null || viewport.getView() != this) {
			return;
		}

		scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
	}
}
 
Example 4
Source File: XTextAreaPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private PropertyChangeListener createPropertyChangeHandler() {
    return new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent e) {
                String propertyName = e.getPropertyName();

                if (propertyName.equals("componentOrientation")) {
                    JScrollPane pane = (JScrollPane)e.getSource();
                    JScrollBar vsb = pane.getVerticalScrollBar();
                    if (vsb != null) {
                        if (isLeftToRight(pane)) {
                            vsbBorder = new CompoundBorder(new EmptyBorder(0, 4, 0, -4),
                                                           vsb.getBorder());
                        } else {
                            vsbBorder = new CompoundBorder(new EmptyBorder(0, -4, 0, 4),
                                                           vsb.getBorder());
                        }
                        vsb.setBorder(vsbBorder);
                    }
                }
            }};
}
 
Example 5
Source File: XTextAreaPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installDefaults(JScrollPane scrollpane) {
    Border b = scrollpane.getBorder();
    UIDefaults uidefaults = XToolkit.getUIDefaults();
    scrollpane.setBorder(uidefaults.getBorder("ScrollPane.border"));
    scrollpane.setBackground(uidefaults.getColor("ScrollPane.background"));
    scrollpane.setViewportBorder(uidefaults.getBorder("TextField.border"));
    JScrollBar vsb = scrollpane.getVerticalScrollBar();
    if (vsb != null) {
        if (isLeftToRight(scrollpane)) {
            vsbBorder = new CompoundBorder(vsbMarginBorderR,
                                           vsb.getBorder());
        }
        else {
            vsbBorder = new CompoundBorder(vsbMarginBorderL,
                                           vsb.getBorder());
        }
        vsb.setBorder(vsbBorder);
    }

    JScrollBar hsb = scrollpane.getHorizontalScrollBar();
    if (hsb != null) {
        hsbBorder = new CompoundBorder(hsbMarginBorder, hsb.getBorder());
        hsb.setBorder(hsbBorder);
    }
}
 
Example 6
Source File: XTextAreaPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private PropertyChangeListener createPropertyChangeHandler() {
    return new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent e) {
                String propertyName = e.getPropertyName();

                if (propertyName.equals("componentOrientation")) {
                    JScrollPane pane = (JScrollPane)e.getSource();
                    JScrollBar vsb = pane.getVerticalScrollBar();
                    if (vsb != null) {
                        if (isLeftToRight(pane)) {
                            vsbBorder = new CompoundBorder(new EmptyBorder(0, 4, 0, -4),
                                                           vsb.getBorder());
                        } else {
                            vsbBorder = new CompoundBorder(new EmptyBorder(0, -4, 0, 4),
                                                           vsb.getBorder());
                        }
                        vsb.setBorder(vsbBorder);
                    }
                }
            }};
}
 
Example 7
Source File: XTextAreaPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installDefaults(JScrollPane scrollpane) {
    Border b = scrollpane.getBorder();
    UIDefaults uidefaults = XToolkit.getUIDefaults();
    scrollpane.setBorder(uidefaults.getBorder("ScrollPane.border"));
    scrollpane.setBackground(uidefaults.getColor("ScrollPane.background"));
    scrollpane.setViewportBorder(uidefaults.getBorder("TextField.border"));
    JScrollBar vsb = scrollpane.getVerticalScrollBar();
    if (vsb != null) {
        if (isLeftToRight(scrollpane)) {
            vsbBorder = new CompoundBorder(vsbMarginBorderR,
                                           vsb.getBorder());
        }
        else {
            vsbBorder = new CompoundBorder(vsbMarginBorderL,
                                           vsb.getBorder());
        }
        vsb.setBorder(vsbBorder);
    }

    JScrollBar hsb = scrollpane.getHorizontalScrollBar();
    if (hsb != null) {
        hsbBorder = new CompoundBorder(hsbMarginBorder, hsb.getBorder());
        hsb.setBorder(hsbBorder);
    }
}
 
Example 8
Source File: TracerDataCompareView.java    From pega-tracerviewer with Apache License 2.0 5 votes vote down vote up
protected void syncScrollBars() {

        JScrollPane jscrollPaneLeft = getjscrollPaneLeft();
        JScrollPane jscrollPaneRight = getjscrollPaneRight();

        JScrollBar jscrollBarLeftH = jscrollPaneLeft.getHorizontalScrollBar();
        JScrollBar jscrollBarLeftV = jscrollPaneLeft.getVerticalScrollBar();
        JScrollBar jscrollBarRightH = jscrollPaneRight.getHorizontalScrollBar();
        JScrollBar jscrollBarRightV = jscrollPaneRight.getVerticalScrollBar();

        jscrollBarRightH.setModel(jscrollBarLeftH.getModel());
        jscrollBarRightV.setModel(jscrollBarLeftV.getModel());
    }
 
Example 9
Source File: SmartScroller.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 *  Specify how the SmartScroller will function.
 *
 *  @param scrollPane the scroll pane to monitor
 *  @param scrollDirection indicates which JScrollBar to monitor.
 *                         Valid values are HORIZONTAL and VERTICAL.
 *  @param viewportPosition indicates where the viewport will normally be
 *                          positioned as data is added.
 *                          Valid values are START and END
 */
public SmartScroller(JScrollPane scrollPane, int scrollDirection, int viewportPosition)
{
	if (scrollDirection != HORIZONTAL
	&&  scrollDirection != VERTICAL)
		throw new IllegalArgumentException("invalid scroll direction specified");

	if (viewportPosition != START
	&&  viewportPosition != END)
		throw new IllegalArgumentException("invalid viewport position specified");

	this.viewportPosition = viewportPosition;

	if (scrollDirection == HORIZONTAL)
		scrollBar = scrollPane.getHorizontalScrollBar();
	else
		scrollBar = scrollPane.getVerticalScrollBar();

	scrollBar.addAdjustmentListener( this );

	//  Turn off automatic scrolling for text components

	Component view = scrollPane.getViewport().getView();

	if (view instanceof JTextComponent)
	{
		JTextComponent textComponent = (JTextComponent)view;
		DefaultCaret caret = (DefaultCaret)textComponent.getCaret();
		caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
	}
}
 
Example 10
Source File: FlatTableHeaderUI.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
private boolean isVerticalScrollBarVisible() {
	JScrollPane scrollPane = getScrollPane();
	return (scrollPane != null && scrollPane.getVerticalScrollBar() != null)
		? scrollPane.getVerticalScrollBar().isVisible()
		: false;
}
 
Example 11
Source File: WrapLayout.java    From Shuffle-Move with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the minimum or preferred dimension needed to layout the target container.
 *
 * @param target
 *           target to get layout size for
 * @param preferred
 *           should preferred size be calculated
 * @return the dimension to layout the target container
 */
private Dimension layoutSize(Container target, boolean preferred) {
   synchronized (target.getTreeLock()) {
      // Each row must fit with the width allocated to the containter.
      // When the container width = 0, the preferred width of the
      // container
      // has not yet been calculated so lets ask for the maximum.
      
      int targetWidth = target.getSize().width;
      
      if (targetWidth == 0) {
         targetWidth = Integer.MAX_VALUE;
      }
      
      int hgap = getHgap();
      int vgap = getVgap();
      Insets insets = target.getInsets();
      int horizontalInsetsAndGap = insets.left + insets.right + hgap * 2;
      int maxWidth = targetWidth - horizontalInsetsAndGap;
      
      // Fit components into the allowed width
      
      Dimension dim = new Dimension(0, 0);
      int rowWidth = 0;
      int rowHeight = 0;
      
      int nmembers = target.getComponentCount();
      
      for (int i = 0; i < nmembers; i++) {
         Component m = target.getComponent(i);
         
         if (m.isVisible()) {
            Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();
            
            // Can't add the component to current row. Start a new row.
            
            if (rowWidth + d.width > maxWidth) {
               addRow(dim, rowWidth, rowHeight);
               rowWidth = 0;
               rowHeight = 0;
            }
            
            // Add a horizontal gap for all components after the first
            
            if (rowWidth != 0) {
               rowWidth += hgap;
            }
            
            rowWidth += d.width;
            rowHeight = Math.max(rowHeight, d.height);
         }
      }
      
      addRow(dim, rowWidth, rowHeight);
      
      dim.width += horizontalInsetsAndGap;
      dim.height += insets.top + insets.bottom + vgap * 2;
      
      // When using a scroll pane or the DecoratedLookAndFeel we need to
      // make sure the preferred size is less than the size of the
      // target containter so shrinking the container size works
      // correctly. Removing the horizontal gap is an easy way to do this.
      
      Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);
      
      if (scrollPane != null && target.isValid()) {
         int extra = 1;
         if (scrollPane instanceof JScrollPane) {
            JScrollPane jsp = (JScrollPane) scrollPane;
            JScrollBar vsb = jsp.getVerticalScrollBar();
            if (vsb != null) {
               extra += Math.max(0, vsb.getWidth());
            }
         }
         dim.width -= hgap + extra;
      }
      
      return dim;
   }
}
 
Example 12
Source File: WhiteBackgroundLookAndFeel.java    From neembuu-uploader with GNU General Public License v3.0 4 votes vote down vote up
public static void themeScrolls(JScrollPane jsp){
    if(jsp.getHorizontalScrollBar()!=null)
        themedScrollBar(jsp.getHorizontalScrollBar());
    if(jsp.getVerticalScrollBar()!=null)
        themedScrollBar(jsp.getVerticalScrollBar());
}
 
Example 13
Source File: ConsolePanel.java    From Qora with MIT License 4 votes vote down vote up
public ConsolePanel()
{
	this.setLayout(new GridBagLayout());
	
	//CREATE SERVICE
	this.client = new ApiClient();//new RpcClient(new RpcServiceImpl());
	
	//PADDING
	this.setBorder(new EmptyBorder(10, 10, 10, 10));
	
	//TEXTAREA GBC
	GridBagConstraints areaGBC = new GridBagConstraints();
	areaGBC.insets = new Insets(5,5,5,5);
	areaGBC.fill = GridBagConstraints.BOTH;  
	areaGBC.anchor = GridBagConstraints.NORTHWEST;
	areaGBC.weighty = 1;	
	areaGBC.weightx = 1;
	areaGBC.gridx = 0;	
	areaGBC.gridy = 0;
	
	//TEXTBOX GBC
	GridBagConstraints txtGBC = new GridBagConstraints();
	txtGBC.insets = new Insets(5,5,5,5);
	txtGBC.fill = GridBagConstraints.HORIZONTAL;  
	txtGBC.anchor = GridBagConstraints.NORTHWEST;
	txtGBC.weightx = 1;
	txtGBC.gridx = 0;	
	txtGBC.gridy = 1;
	
	//TEXTAREA
	this.areaConsole = new JTextArea();
	this.areaConsole.setLineWrap(true);
	this.areaConsole.setEditable(false);
	JScrollPane scrollPane = new JScrollPane(this.areaConsole);
	JScrollBar vertical = scrollPane.getVerticalScrollBar();
       vertical.setValue(vertical.getMaximum());
	this.add(scrollPane, areaGBC);
	
	//TEXTFIELD
	this.txtCommand = new JTextField();
	this.txtCommand.addActionListener(new ActionListener()
	{
		public void actionPerformed(ActionEvent e)
           {
			//GET COMMAND
			String command = txtCommand.getText();
			areaConsole.append("[COMMAND] " + command + "\n");
			
			//EMPTY COMMAND FIELD
			txtCommand.setText("");
			
			//GET RESULT
			String result = client.executeCommand(command);
			
			//APPEND RESULT
			areaConsole.append("[RESULT] " + result + "\n");
           }
	});
	this.add(this.txtCommand, txtGBC);
}
 
Example 14
Source File: DebugTabPane.java    From Qora with MIT License 4 votes vote down vote up
public DebugTabPane()
{
	super();
	
	//ADD TABS
       this.addTab("Console", new ConsolePanel());
	
       this.peersTableModel = new PeersTableModel();
	this.addTab("Peers", new JScrollPane(Gui.createSortableTable(this.peersTableModel, 0)));
       
	//TRANSACTIONS TABLE MODEL
	this.transactionsTableModel = new TransactionsTableModel();
	this.transactionsTable = new JTable(this.transactionsTableModel);
	
	//TRANSACTIONS SORTER
	Map<Integer, Integer> indexes = new TreeMap<Integer, Integer>();
	indexes.put(TransactionsTableModel.COLUMN_TIMESTAMP, TransactionMap.TIMESTAMP_INDEX);
	QoraRowSorter sorter = new QoraRowSorter(transactionsTableModel, indexes);
	transactionsTable.setRowSorter(sorter);
	
	//TRANSACTION DETAILS
	this.transactionsTable.addMouseListener(new MouseAdapter() 
	{
		public void mouseClicked(MouseEvent e) 
		{
			if(e.getClickCount() == 2) 
			{
				//GET ROW
		        int row = transactionsTable.getSelectedRow();
		        row = transactionsTable.convertRowIndexToModel(row);
		        
		        //GET TRANSACTION
		        Transaction transaction = transactionsTableModel.getTransaction(row);
		         
		        //SHOW DETAIL SCREEN OF TRANSACTION
		        TransactionDetailsFactory.getInstance().createTransactionDetail(transaction);
		    }
		}
	});
	
	//ADD TRANSACTIONS TABLE
	this.addTab("Transactions", new JScrollPane(this.transactionsTable)); 
           
	//BLOCKS TABLE MODEL
	this.blocksTableModel = new BlocksTableModel();
	JTable blocksTable = new JTable(this.blocksTableModel);
	
	//BLOCKS SORTER
	indexes = new TreeMap<Integer, Integer>();
	indexes.put(BlocksTableModel.COLUMN_HEIGHT, BlockMap.HEIGHT_INDEX);
	sorter = new QoraRowSorter(blocksTableModel, indexes);
	blocksTable.setRowSorter(sorter);
	
	//ADD BLOCK TABLE
	this.addTab("Blocks", new JScrollPane(blocksTable));
	
       this.loggerTextArea = new LoggerTextArea(Logger.getGlobal());
       JScrollPane scrollPane = new JScrollPane(this.loggerTextArea);
       JScrollBar vertical = scrollPane.getVerticalScrollBar();
       vertical.setValue(vertical.getMaximum());
       this.addTab("Logger", scrollPane);
}
 
Example 15
Source File: CustomScroll.java    From mars-sim with GNU General Public License v3.0 3 votes vote down vote up
public CustomScroll(JComponent component) {
        scr = new JScrollPane(component);
        scr.setBorder(null);
        scr.setViewportBorder(null);
        scr.setBorder(BorderFactory.createEmptyBorder());
        scr.getViewport().setOpaque(false);
//        scr.setOpaque(false);
//        scr.setBackground(new Color(0, 0, 0, 5));
        verticalScrollBar = scr.getVerticalScrollBar();
        verticalScrollBar.setVisible(false);
        verticalScrollBar.setOpaque(false);
        verticalScrollBar.setUI(new MyScrollBarUI());
        verticalScrollBar.setUnitIncrement(16);

        horizontalScrollBar = scr.getHorizontalScrollBar();
        horizontalScrollBar.setVisible(false);
        horizontalScrollBar.setOpaque(false);
        horizontalScrollBar.setUI(new MyScrollBarUI());

        JLayeredPane layeredPane = new JLayeredPane();
        layeredPane.setLayer(verticalScrollBar, JLayeredPane.PALETTE_LAYER);
        layeredPane.setLayer(horizontalScrollBar, JLayeredPane.PALETTE_LAYER);

        scr.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scr.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scr.setLayout(new ScrollPaneLayout() {
            @Override
            public void layoutContainer(Container parent) {
                viewport.setBounds(0, 0, getWidth(), getHeight());
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        displayScrollBarsIfNecessary(viewport);
                    }
                });
            }
        });

        layeredPane.add(horizontalScrollBar);
        layeredPane.add(verticalScrollBar);
        layeredPane.add(scr);

        setLayout(new BorderLayout() {
            @Override
            public void layoutContainer(Container target) {
                super.layoutContainer(target);
                int width = getWidth();
                int height = getHeight();
                scr.setBounds(0, 0, width, height);

                int scrollBarSize = 10;
                int cornerOffset = verticalScrollBar.isVisible() &&
                        horizontalScrollBar.isVisible() ? scrollBarSize : 0;
                if (verticalScrollBar.isVisible()) {
                    verticalScrollBar.setBounds(width - scrollBarSize, 0,
                            scrollBarSize, height - cornerOffset);
                }
                if (horizontalScrollBar.isVisible()) {
                    horizontalScrollBar.setBounds(0, height - scrollBarSize,
                            width - cornerOffset, scrollBarSize);
                }
            }
        });
        add(layeredPane, BorderLayout.CENTER);
        layeredPane.setBackground(Color.BLUE);
    }