Java Code Examples for javax.swing.JScrollBar#setValue()

The following examples show how to use javax.swing.JScrollBar#setValue() . 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: MyView.java    From JPPF with Apache License 2.0 6 votes vote down vote up
/**
 * This method adds a new entry to the messages log.
 * @param message the message to add.
 */
private void newMessage(final String message) {
  // create and format a timestamp
  final String date = sdf.format(new Date());
  // add the new, timestamped message to the log
  final String formatted = String.format("[%s] %s", date, message);
  synchronized(this) {
    logSize++;
    // if number of log entries > max, remove the oldest ones
    while (logSize > MAX_MESSAGES) {
      logSize--;
      listModel.remove(0);
    }
    // add the log entry to the JList
    listModel.addElement(formatted);
    // scroll to the end of the log
    final JScrollBar scrollBar = listScroller.getVerticalScrollBar();
    scrollBar.setValue(scrollBar.getMaximum());
  }
}
 
Example 2
Source File: KeywordsPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked when an action occurs.
 */
public void actionPerformed(ActionEvent evt) {
    Object source = evt.getSource();
    if (source == moreButton) {
        ConditionPanel comp = addCondition(true, null);
        JScrollBar vsb = conditionsScrollPane.getVerticalScrollBar();
        vsb.setValue(vsb.getMaximum());
        comp.focusPropertyCombo();
    } else if (source == fewerButton) {
        conditionsPanel.remove(conditionsPanel.getComponentCount() - 1);
        invalidate();
        getParent().validate();
        repaint();
    }
    updateSensitivity();
    putClientProperty(FilterCondition.PROP_VALUE_VALID, Boolean.valueOf(isValueValid()));
}
 
Example 3
Source File: LWTextAreaPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void insert(final String text, final int pos) {
    final ScrollableJTextArea pane = getDelegate();
    synchronized (getDelegateLock()) {
        final JTextArea area = pane.getView();
        final boolean doScroll = pos >= area.getDocument().getLength()
                                 && area.getDocument().getLength() != 0;
        area.insert(text, pos);
        revalidate();
        if (doScroll) {
            final JScrollBar vbar = pane.getVerticalScrollBar();
            if (vbar != null) {
                vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
            }
        }
    }
    repaintPeer();
}
 
Example 4
Source File: LWTextAreaPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void insert(final String text, final int pos) {
    final ScrollableJTextArea pane = getDelegate();
    synchronized (getDelegateLock()) {
        final JTextArea area = pane.getView();
        final boolean doScroll = pos >= area.getDocument().getLength()
                                 && area.getDocument().getLength() != 0;
        area.insert(text, pos);
        revalidate();
        if (doScroll) {
            final JScrollBar vbar = pane.getVerticalScrollBar();
            if (vbar != null) {
                vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
            }
        }
    }
    repaintPeer();
}
 
Example 5
Source File: LWTextAreaPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void insert(final String text, final int pos) {
    final ScrollableJTextArea pane = getDelegate();
    synchronized (getDelegateLock()) {
        final JTextArea area = pane.getView();
        final boolean doScroll = pos >= area.getDocument().getLength()
                                 && area.getDocument().getLength() != 0;
        area.insert(text, pos);
        revalidate();
        if (doScroll) {
            final JScrollBar vbar = pane.getVerticalScrollBar();
            if (vbar != null) {
                vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
            }
        }
    }
    repaintPeer();
}
 
Example 6
Source File: SeaGlassScrollPaneUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
void scrollByBlock(JScrollBar scrollbar, int direction) {
    // This method is called from BasicScrollPaneUI to implement wheel
    // scrolling, and also from scrollByBlock().
    int oldValue = scrollbar.getValue();
    int blockIncrement = scrollbar.getBlockIncrement(direction);
    int delta = blockIncrement * ((direction > 0) ? +1 : -1);
    int newValue = oldValue + delta;

    // Check for overflow.
    if (delta > 0 && newValue < oldValue) {
        newValue = scrollbar.getMaximum();
    } else if (delta < 0 && newValue > oldValue) {
        newValue = scrollbar.getMinimum();
    }

    scrollbar.setValue(newValue);
}
 
Example 7
Source File: LWTextAreaPeer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void insert(final String text, final int pos) {
    final ScrollableJTextArea pane = getDelegate();
    synchronized (getDelegateLock()) {
        final JTextArea area = pane.getView();
        final boolean doScroll = pos >= area.getDocument().getLength()
                                 && area.getDocument().getLength() != 0;
        area.insert(text, pos);
        revalidate();
        if (doScroll) {
            final JScrollBar vbar = pane.getVerticalScrollBar();
            if (vbar != null) {
                vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
            }
        }
    }
    repaintPeer();
}
 
Example 8
Source File: XTextAreaPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * insert the text "txt on position "pos" in the array lines
 * @see java.awt.peer.TextAreaPeer
 */
@Override
public void insert(String txt, int p) {
    if (jtext != null) {
        boolean doScroll = (p >= jtext.getDocument().getLength() && jtext.getDocument().getLength() != 0);
        jtext.insert(txt,p);
        textPane.validate();
        if (doScroll) {
            JScrollBar bar = textPane.getVerticalScrollBar();
            if (bar != null) {
                bar.setValue(bar.getMaximum()-bar.getVisibleAmount());
            }
        }
    }
}
 
Example 9
Source File: JavaOverviewSummary.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static void scroll(JScrollBar scroller, MouseWheelEvent event) {
            if (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
                int direction = event.getUnitsToScroll() < 0 ? -1 : 1;
                int increment = scroller.getUnitIncrement(direction);
//                int amount = event.getScrollAmount();
                int amount = 1;
                int oldValue = scroller.getValue();
                int newValue = oldValue + increment * amount * direction;
                if (oldValue != newValue) scroller.setValue(newValue);
                event.consume();
            }
        }
 
Example 10
Source File: XTextAreaPeer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * insert the text "txt on position "pos" in the array lines
 * @see java.awt.peer.TextAreaPeer
 */
@Override
public void insert(String txt, int p) {
    if (jtext != null) {
        boolean doScroll = (p >= jtext.getDocument().getLength() && jtext.getDocument().getLength() != 0);
        jtext.insert(txt,p);
        textPane.validate();
        if (doScroll) {
            JScrollBar bar = textPane.getVerticalScrollBar();
            if (bar != null) {
                bar.setValue(bar.getMaximum()-bar.getVisibleAmount());
            }
        }
    }
}
 
Example 11
Source File: ProfilerTableContainer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void scroll(JScrollBar scroller, MouseWheelEvent event) {
    if (event.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
        int direction = event.getUnitsToScroll() < 0 ? -1 : 1;
        int increment = scroller.getUnitIncrement(direction);
        int amount = event.getScrollAmount();
        int oldValue = scroller.getValue();
        int newValue = oldValue + increment * amount * direction;
        if (oldValue != newValue) scroller.setValue(newValue);
        event.consume();
    }
}
 
Example 12
Source File: XTextAreaPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * insert the text "txt on position "pos" in the array lines
 * @see java.awt.peer.TextAreaPeer
 */
@Override
public void insert(String txt, int p) {
    if (jtext != null) {
        boolean doScroll = (p >= jtext.getDocument().getLength() && jtext.getDocument().getLength() != 0);
        jtext.insert(txt,p);
        textPane.validate();
        if (doScroll) {
            JScrollBar bar = textPane.getVerticalScrollBar();
            if (bar != null) {
                bar.setValue(bar.getMaximum()-bar.getVisibleAmount());
            }
        }
    }
}
 
Example 13
Source File: LogFrame.java    From finalspeed-91yun with GNU General Public License v2.0 5 votes vote down vote up
void showText(String text){
	logArea.append(text);
	trunkTextArea(logArea);
	if(autoScroll){
		JScrollBar vertical = scroll.getVerticalScrollBar();
		vertical.setValue(vertical.getMaximum() );
	}
}
 
Example 14
Source File: ScrollView.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void actionPerformed (ActionEvent e)
{
    final JScrollBar vertical = component.getVerticalScrollBar();
    vertical.setValue(vertical.getValue() + 1);
}
 
Example 15
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 16
Source File: TabPanel.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * Constructor
	 *
	 * @param tabTitle   the title to be displayed in the tab (may be null).
	 * @param tabIcon    the icon to be displayed in the tab (may be null).
	 * @param tabToolTip the tool tip to be displayed in the icon (may be null).
	 * @param unit       the unit to display.
	 * @param desktop    the main desktop.
	 */
	public TabPanel(String tabTitle, Icon tabIcon, String tabToolTip, Unit unit, MainDesktopPane desktop) {

		// Use JScrollPane constructor
		super();

		// Initialize data members
		this.tabTitle = tabTitle;
		this.tabIcon = tabIcon;
		this.tabToolTip = tabToolTip;
		this.unit = unit;
		this.desktop = desktop;

		if (unit instanceof Person) {
			this.setMaximumSize(new Dimension(UnitWindow.WIDTH - 30, UnitWindow.HEIGHT - 140));
			this.setPreferredSize(new Dimension(UnitWindow.WIDTH - 30, UnitWindow.HEIGHT - 140));
		}
		else {
			this.setMaximumSize(new Dimension(UnitWindow.WIDTH - 30, UnitWindow.HEIGHT - 90));
			this.setPreferredSize(new Dimension(UnitWindow.WIDTH - 30, UnitWindow.HEIGHT - 90));
		}
		
		// Create the view panel
		viewPanel = new JPanel(new BorderLayout(0, 0));
		createViewport();
		setViewportView(viewPanel);
		createVerticalScrollBar();
		setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);

		JScrollBar vertical = getVerticalScrollBar();
		vertical.setValue(0);//vertical.getMinimum());
		
		// Create top content panel
		topContentPanel = new JPanel();
		topContentPanel.setLayout(new BoxLayout(topContentPanel, BoxLayout.Y_AXIS));
		topContentPanel.setBorder(MainDesktopPane.newEmptyBorder());
		viewPanel.add(topContentPanel, BorderLayout.NORTH);

//		Border border = new MarsPanelBorder();
		Border margin = new EmptyBorder(5,5,5,5);
		
		// Create center content panel
		centerContentPanel = new JPanel(new BorderLayout(0, 10));
//		centerContentPanel.setBorder(new CompoundBorder(border, margin));
		centerContentPanel.setBorder(margin);
		viewPanel.add(centerContentPanel, BorderLayout.CENTER);

		// setBorder(new DropShadowBorder(Color.BLACK, 0, 11, .2f, 16,false, true, true,
		// true));
	}
 
Example 17
Source File: ScrollView.java    From audiveris with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void actionPerformed (ActionEvent e)
{
    final JScrollBar vertical = component.getVerticalScrollBar();
    vertical.setValue(vertical.getValue() - 1);
}
 
Example 18
Source File: SmartScroller.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private void checkScrollBar(AdjustmentEvent e)
{
	//  The scroll bar listModel contains information needed to determine
	//  whether the viewport should be repositioned or not.

	JScrollBar scrollBar = (JScrollBar)e.getSource();
	BoundedRangeModel listModel = scrollBar.getModel();
	int value = listModel.getValue();
	int extent = listModel.getExtent();
	int maximum = listModel.getMaximum();

	boolean valueChanged = previousValue != value;
	boolean maximumChanged = previousMaximum != maximum;

	//  Check if the user has manually repositioned the scrollbar

	if (valueChanged && !maximumChanged)
	{
		if (viewportPosition == START)
			adjustScrollBar = value != 0;
		else
			adjustScrollBar = value + extent >= maximum;
	}

	//  Reset the "value" so we can reposition the viewport and
	//  distinguish between a user scroll and a program scroll.
	//  (ie. valueChanged will be false on a program scroll)

	if (adjustScrollBar && viewportPosition == END)
	{
		//  Scroll the viewport to the end.
		scrollBar.removeAdjustmentListener( this );
		value = maximum - extent;
		scrollBar.setValue( value );
		scrollBar.addAdjustmentListener( this );
	}

	if (adjustScrollBar && viewportPosition == START)
	{
		//  Keep the viewport at the same relative viewportPosition
		scrollBar.removeAdjustmentListener( this );
		value = value + maximum - previousMaximum;
		scrollBar.setValue( value );
		scrollBar.addAdjustmentListener( this );
	}

	previousValue = value;
	previousMaximum = maximum;
}
 
Example 19
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 20
Source File: FastCopyMainForm.java    From FastCopy with Apache License 2.0 4 votes vote down vote up
public void scrollToBottom() {
	outputTextArea.validate();
	JScrollBar vertical = outputTextAreaScrollPane.getVerticalScrollBar();
	vertical.setValue(vertical.getMaximum());
}