本文整理匯總了Java中javax.swing.JScrollBar類的典型用法代碼示例。如果您正苦於以下問題:Java JScrollBar類的具體用法?Java JScrollBar怎麽用?Java JScrollBar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JScrollBar類屬於javax.swing包,在下文中一共展示了JScrollBar類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import javax.swing.JScrollBar; //導入依賴的package包/類
public void run() {
if (this.bar == null) {
this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100);
this.bar.setPreferredSize(new Dimension(400, 20));
JFrame frame = new JFrame();
frame.add(this.bar);
frame.pack();
frame.setVisible(true);
}
else if (40 != this.bar.getValue()) {
System.out.println("name = " + UIManager.getLookAndFeel().getName());
System.out.println("value = " + this.bar.getValue());
}
else {
SwingUtilities.getWindowAncestor(this.bar).dispose();
this.bar = null;
}
}
示例2: doZoom
import javax.swing.JScrollBar; //導入依賴的package包/類
void doZoom( Point p, double factor ) {
if( scPane == null || ( tracksWidth && tracksHeight ))return;
Insets ins = axes.getInsets();
Rectangle rect = getVisibleRect();
double x = (double)(p.x-ins.left) / zoom;
double y = (double)(p.y-ins.top) / zoom;
double w = (double) (rect.width - ins.left - ins.right);
double h = (double) (rect.height - ins.top - ins.bottom);
zoom *= factor;
int newX = (int) (x*zoom - w*.5d);
int newY = (int) (y*zoom - h*.5d);
invalidate();
scPane.validate();
JScrollBar sb;
if(!tracksWidth) {
sb = scPane.getHorizontalScrollBar();
sb.setValue(newX);
}
if(!tracksHeight) {
sb = scPane.getVerticalScrollBar();
sb.setValue(newY);
}
revalidate();
}
示例3: updateHorizontalScrollBars
import javax.swing.JScrollBar; //導入依賴的package包/類
private void updateHorizontalScrollBars(ProfilerTable table, int column, boolean layout) {
if (column != -1) {
JScrollBar scroll = getScroller(column);
int offset = table.getColumnOffset(column);
int columnPref = table.getColumnPreferredWidth(column);
int _column = table.convertColumnIndexToView(column);
int columnAct = table.getTableHeader().getHeaderRect(_column).width;
if (columnPref > columnAct) {
int value = Math.min(offset, columnPref - columnAct);
scroll.setValues(value, columnAct, 0, columnPref);
} else {
scroll.setValues(0, 0, 0, 0);
}
}
if (layout) {
doLayout();
scrollersPanel.doLayout();
repaint();
}
}
示例4: doZoom
import javax.swing.JScrollBar; //導入依賴的package包/類
public void doZoom( Point p, double factor ) {
Rectangle rect = getVisibleRect();
double x = p.getX() / zoom;
double y = p.getY() / zoom;
double w = rect.getWidth();
double h = rect.getHeight();
zoom *= factor;
zoomX = zoomY = zoom;
int newX = (int) (x*zoom - w*.5d);
int newY = (int) (y*zoom - h*.5d);
invalidate();
scrollPane.validate();
JScrollBar sb = scrollPane.getHorizontalScrollBar();
sb.setValue(newX);
sb = scrollPane.getVerticalScrollBar();
sb.setValue(newY);
repaint();
}
示例5: reset
import javax.swing.JScrollBar; //導入依賴的package包/類
public static void reset() {
entries.clear();
add(Component.class, RUnknownComponent.class);
add(Window.class, RWindow.class);
add(JTable.class, RTable.class);
add(JTableHeader.class, RTableHeader.class);
add(AbstractButton.class, RAbstractButton.class);
add(JToggleButton.class, RToggleButton.class);
add(JComboBox.class, RComboBox.class);
add(JTextComponent.class, RTextComponent.class);
add(JTree.class, RTree.class);
add(JList.class, RList.class);
add(JTabbedPane.class, RTabbedPane.class);
add(JMenuItem.class, RMenuItem.class);
add(JSlider.class, RSlider.class);
add(JProgressBar.class, RProgressBar.class);
add(JSpinner.class, RSpinner.class);
add(DefaultEditor.class, RDefaultEditor.class);
add(JColorChooser.class, RColorChooser.class);
add(JSplitPane.class, RSplitPane.class);
add(BasicSplitPaneDivider.class, RSplitPane.class);
add(JFileChooser.class, RFileChooser.class);
add(JEditorPane.class, REditorPane.class);
add(JLabel.class, RLabel.class);
add(JScrollBar.class, RIgnoreComponent.class);
}
示例6: print
import javax.swing.JScrollBar; //導入依賴的package包/類
public void print(String string) {
System.out.print(string);
Document document = this.textArea.getDocument();
final JScrollBar scrollBar = this.scrollPane.getVerticalScrollBar();
boolean shouldScroll = (scrollBar.getValue() + scrollBar.getSize().getHeight() +
MONOSPACED.getSize() * 2 > scrollBar.getMaximum());
try {
document.insertString(document.getLength(), string, null);
} catch (BadLocationException ignored) {
}
if (shouldScroll) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
scrollBar.setValue(2147483647);
}
});
}
}
示例7: initializeImpl
import javax.swing.JScrollBar; //導入依賴的package包/類
@Override
void initializeImpl() {
super.initializeImpl();
final Scrollbar target = getTarget();
setLineIncrement(target.getUnitIncrement());
setPageIncrement(target.getBlockIncrement());
setValues(target.getValue(), target.getVisibleAmount(),
target.getMinimum(), target.getMaximum());
final int orientation = target.getOrientation();
final JScrollBar delegate = getDelegate();
synchronized (getDelegateLock()) {
delegate.setOrientation(orientation == Scrollbar.HORIZONTAL
? Adjustable.HORIZONTAL
: Adjustable.VERTICAL);
delegate.addAdjustmentListener(this);
}
}
示例8: getMinimumSize
import javax.swing.JScrollBar; //導入依賴的package包/類
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
final Dimension size = super.getMinimumSize(rows, columns);
synchronized (getDelegateLock()) {
// JScrollPane insets
final Insets pi = getDelegate().getInsets();
size.width += pi.left + pi.right;
size.height += pi.top + pi.bottom;
// Take scrollbars into account.
final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
final JScrollBar vbar = getDelegate().getVerticalScrollBar();
size.width += vbar != null ? vbar.getMinimumSize().width : 0;
}
final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
size.height += hbar != null ? hbar.getMinimumSize().height : 0;
}
}
return size;
}
示例9: insert
import javax.swing.JScrollBar; //導入依賴的package包/類
@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();
}
示例10: uninstallDefaults
import javax.swing.JScrollBar; //導入依賴的package包/類
@Override
protected void uninstallDefaults(JScrollPane c) {
super.uninstallDefaults(c);
JScrollBar vsb = scrollpane.getVerticalScrollBar();
if (vsb != null) {
if (vsb.getBorder() == vsbBorder) {
vsb.setBorder(null);
}
vsbBorder = null;
}
JScrollBar hsb = scrollpane.getHorizontalScrollBar();
if (hsb != null) {
if (hsb.getBorder() == hsbBorder) {
hsb.setBorder(null);
}
hsbBorder = null;
}
}
示例11: setPointerIfPointOverScrollbar
import javax.swing.JScrollBar; //導入依賴的package包/類
private boolean setPointerIfPointOverScrollbar( JScrollBar bar, Point point ) {
if ( ! bar.getBounds().contains( point ) ) {
return false;
}
current.setBar( bar );
Point local = toLocalSpace( bar, point );
XTextAreaPeer.XAWTScrollBarUI ui =
(XTextAreaPeer.XAWTScrollBarUI) bar.getUI();
if ( ! setPointerIfPointOverButton( ui.getIncreaseButton(), local ) ) {
setPointerIfPointOverButton( ui.getDecreaseButton(), local );
}
return true;
}
示例12: maintainScrollBar
import javax.swing.JScrollBar; //導入依賴的package包/類
/**
*
*/
protected void maintainScrollBar(boolean horizontal, double factor,
boolean center)
{
JScrollBar scrollBar = (horizontal) ? getHorizontalScrollBar()
: getVerticalScrollBar();
if (scrollBar != null)
{
BoundedRangeModel model = scrollBar.getModel();
int newValue = (int) Math.round(model.getValue() * factor)
+ (int) Math.round((center) ? (model.getExtent()
* (factor - 1) / 2) : 0);
model.setValue(newValue);
}
}
示例13: scrollTo
import javax.swing.JScrollBar; //導入依賴的package包/類
public void scrollTo (int t) {
if(cruise==null) return;
int i=0;
int x=0;
while( i<cruise.start.length && cruise.start[i]<t ) i++;
if( i==cruise.start.length ) {
x = width;
} else if( t<cruise.start[i] ) {
x = cruise.xPosition[i];
} else if( t>cruise.start[i]+30*cruise.panelSize[i][0] ) {
x = cruise.xPosition[i] + cruise.panelSize[i][0];
} else {
x = cruise.xPosition[i] + (t-cruise.start[i])/30;
}
Rectangle r = getVisibleRect();
x = (int) (x*zoomX) - r.width/2;
JScrollBar sb = scrollPane.getHorizontalScrollBar();
sb.setValue(x);
repaint();
}
示例14: init
import javax.swing.JScrollBar; //導入依賴的package包/類
private static void init(Container container) {
container.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 1;
JLabel label = new JLabel();
Dimension size = new Dimension(111, 0);
label.setPreferredSize(size);
label.setMinimumSize(size);
container.add(label, gbc);
gbc.gridx = 1;
gbc.weightx = 1;
container.add(new JScrollBar(JScrollBar.HORIZONTAL, 1, 111, 1, 1111), gbc);
gbc.gridx = 2;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 1;
container.add(new JScrollBar(JScrollBar.VERTICAL, 1, 111, 1, 1111), gbc);
}
示例15: getScrollDirection
import javax.swing.JScrollBar; //導入依賴的package包/類
@Override
public int getScrollDirection(JScrollBarOperator oper) {
Point toPoint = SwingUtilities.
convertPoint(comp, x, y, getViewport().getView());
int to = (orientation == JScrollBar.HORIZONTAL) ? toPoint.x : toPoint.y;
int ln = (orientation == JScrollBar.HORIZONTAL) ? width : height;
int lv = (orientation == JScrollBar.HORIZONTAL) ? getViewport().getWidth() : getViewport().getHeight();
int vl = oper.getValue();
if (to < vl) {
return ScrollAdjuster.DECREASE_SCROLL_DIRECTION;
} else if ((to + ln - 1) > (vl + lv)
&& to > vl) {
return ScrollAdjuster.INCREASE_SCROLL_DIRECTION;
} else {
return ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION;
}
}