📄 jslider.java
字号:
{ return sliderModel; } /** * This method changes the "model" property. It also needs to unregister * any listeners to the old model and register any listeners to the new * model. * * @param model The model to use with the slider. */ public void setModel(BoundedRangeModel model) { // I didn't do the null pointer check on purpose. // If you try it with Sun's, it'll go ahead and set it to null // and bork the next time it tries to access the model. if (model != sliderModel) { BoundedRangeModel oldModel = sliderModel; sliderModel = model; oldModel.removeChangeListener(changeListener); sliderModel.addChangeListener(changeListener); firePropertyChange("model", oldModel, sliderModel); } } /** * This method returns the minimum value of the slider. * * @return The minimum value of the slider. */ public int getMinimum() { return sliderModel.getMinimum(); } /** * This method sets the minimum value of the slider. * * @param minimum The minimum value of the slider. */ public void setMinimum(int minimum) { int old = sliderModel.getMinimum(); sliderModel.setMinimum(minimum); if (minimum != old) firePropertyChange("minimum", old, minimum); } /** * This method returns the maximum value of the slider. * * @return The maximum value of the slider. */ public int getMaximum() { return sliderModel.getMaximum(); } /** * This method sets the maximum value of the slider. * * @param maximum The maximum value of the slider. */ public void setMaximum(int maximum) { int old = sliderModel.getMaximum(); sliderModel.setMaximum(maximum); if (maximum != old) firePropertyChange("maximum", old, maximum); } /** * This method returns this slider's isAdjusting value which is true if the * thumb is being dragged. * * @return The slider's isAdjusting value. */ public boolean getValueIsAdjusting() { return sliderModel.getValueIsAdjusting(); } /** * This method sets the isAdjusting value for the slider. * * @param adjusting The slider's isAdjusting value. */ public void setValueIsAdjusting(boolean adjusting) { sliderModel.setValueIsAdjusting(adjusting); } /** * This method returns the extent value for this slider. * * @return The extent value for this slider. */ public int getExtent() { return sliderModel.getExtent(); } /** * This method sets the extent value for this slider. * * @param extent The extent value for this slider. */ public void setExtent(int extent) { sliderModel.setExtent(extent); } /** * This method returns the slider orientation. * * @return The orientation of the slider. */ public int getOrientation() { return orientation; } /** * This method changes the "orientation" property of this slider. If the * orientation is not VERTICAL or HORIZONTAL, this method does nothing. * * @param orientation The orientation of this slider. */ public void setOrientation(int orientation) { if (orientation != VERTICAL && orientation != HORIZONTAL) throw new IllegalArgumentException("orientation must be one of: VERTICAL, HORIZONTAL"); if (orientation != this.orientation) { int oldOrientation = this.orientation; this.orientation = orientation; firePropertyChange("orientation", oldOrientation, this.orientation); } } /** * This method returns the label table for this slider. * * @return The label table for this slider. */ public Dictionary getLabelTable() { return labelTable; } /** * This method changes the "labelTable" property of this slider. * * @param table The label table for this slider. */ public void setLabelTable(Dictionary table) { if (table != labelTable) { Dictionary oldTable = labelTable; labelTable = table; firePropertyChange("labelTable", oldTable, labelTable); } } /** * This method is called to reset UI delegates for the labels in the * labelTable to a default for the current look and feel. */ protected void updateLabelUIs() { if (labelTable == null) return; for (Enumeration list = labelTable.elements(); list.hasMoreElements();) { JLabel label = (JLabel) list.nextElement(); label.updateUI(); } } /** * Creates a hashtable of (Integer, JLabel) pairs that can be used as a * label table for this slider. The labels will start from the sliders * minimum and increase by the increment. Each label will have a text * string indicating their integer value. * * @param increment The increment between labels (must be > 0). * * @return A hashtable with the labels and their keys. * * @throws IllegalArgumentException if <code>increment</code> is not greater * than zero. */ public Hashtable createStandardLabels(int increment) { return createStandardLabels(increment, sliderModel.getMinimum()); } /** * Creates a hashtable of (Integer, JLabel) pairs that can be used as a * label table for this slider. The labels will start from the given start * value and increase by the increment. Each label will have a text string * indicating its integer value. * * @param increment The increment between labels (must be > 0). * @param start The value to start from. * * @return A hashtable with the labels and their keys. * * @throws IllegalArgumentException if <code>increment</code> is not greater * than zero, or <code>start</code> is not within the range of the * model. */ public Hashtable createStandardLabels(int increment, int start) { if (increment <= 0) throw new IllegalArgumentException("Requires 'increment' > 0."); if (start < getMinimum() || start > getMaximum()) throw new IllegalArgumentException("The 'start' value is out of range."); Hashtable table = new Hashtable(); JLabel label; Dimension dim; int max = sliderModel.getMaximum(); for (int i = start; i <= max; i += increment) { label = new JLabel(String.valueOf(i)); label.setVerticalAlignment(CENTER); label.setHorizontalAlignment(CENTER); // Make sure these labels have the width and height // they want. dim = label.getPreferredSize(); label.setBounds(label.getX(), label.getY(), (int) dim.getWidth(), (int) dim.getHeight()); table.put(new Integer(i), label); } return table; } /** * This method returns whether the slider is inverted. Horizontal sliders * that are not inverted will have the minimums on the left. If they are * inverted, the minimums will be on the right. Vertical sliders that are * not inverted will have the minimums at the bottom. If they are inverted, * the minimums will be at the top. * * @return Whether this slider is inverted. */ public boolean getInverted() { return isInverted; } /** * This method changes the "inverted" property for this slider.Horizontal * sliders that are not inverted will have the minimums on the left. If * they are inverted, the minimums will be on the right. Vertical sliders * that are not inverted will have the minimums at the bottom. If they are * inverted, the minimums will be at the top. However, if the slider's * componentOrientation is set to RIGHT_TO_LEFT, then everything gets * reversed again. * * @param inverted Whether the slider should be inverted. */ public void setInverted(boolean inverted) { if (isInverted != inverted) { boolean oldInverted = isInverted; isInverted = inverted; firePropertyChange("inverted", oldInverted, isInverted); } } /** * This method returns the amount of units between each major tick mark. * * @return The amount of units between each major tick mark. */ public int getMajorTickSpacing() { return majorTickSpacing; } /** * This method changes the "majorTickSpacing" property for this slider. The * major tick spacing is the amount of units between each major tick mark. * * @param spacing The amount of units between each major tick mark. */ public void setMajorTickSpacing(int spacing) { if (majorTickSpacing != spacing) { int oldSpacing = majorTickSpacing; majorTickSpacing = spacing; firePropertyChange("majorTickSpacing", oldSpacing, majorTickSpacing); } } /** * This method returns the amount of units between each minor tick mark. * * @return The amount of units between each minor tick mark. */ public int getMinorTickSpacing() { return minorTickSpacing; } /** * This method changes the "minorTickSpacing" property for this slider. The * minor tick spacing is the amount of units between each minor tick mark. * * @param spacing The amount of units between each minor tick mark. */ public void setMinorTickSpacing(int spacing) { if (minorTickSpacing != spacing) { int oldSpacing = minorTickSpacing; minorTickSpacing = spacing; firePropertyChange("minorTickSpacing", oldSpacing, minorTickSpacing); } } /** * This method returns whether this slider is snapping to ticks. Sliders * that snap to ticks will automatically move the thumb to the nearest tick * mark. * * @return Whether this slider snaps to ticks. */ public boolean getSnapToTicks() { return snapToTicks; } /** * This method sets whether this slider will snap to ticks. Sliders that * snap to ticks will automatically move the thumb to the nearest tick * mark. * * @param snap Whether this slider snaps to ticks. */ public void setSnapToTicks(boolean snap) { if (snap != snapToTicks) { snapToTicks = snap; firePropertyChange("snapToTicks", !snap, snap); } } /** * This method returns whether the slider will paint its tick marks. In * addition to setting this property to true, one of minor tick spacing or * major tick spacing must be set to a value greater than 0 in order for * ticks to be painted. * * @return Whether ticks will be painted. */ public boolean getPaintTicks() { return paintTicks; } /** * This method changes the "paintTicks" property for this slider. In * addition to setting this property to true, one of minor tick spacing or * major tick spacing must be set to a value greater than 0 in order for * ticks to be painted. * * @param paint Whether ticks will be painted. */ public void setPaintTicks(boolean paint) { if (paint != paintTicks) { boolean oldPaintTicks = paintTicks; paintTicks = paint; firePropertyChange("paintTicks", oldPaintTicks, paintTicks); } } /** * This method returns whether the track will be painted. * * @return Whether the track will be painted. */ public boolean getPaintTrack() { return paintTrack; } /** * Sets the flag that controls whether or not the track is painted, and * sends a {@link PropertyChangeEvent} (for the "paintTrack" property) to all * registered listeners. * * @param paint Whether the track will be painted. */ public void setPaintTrack(boolean paint) { if (paintTrack != paint) { paintTrack = paint; firePropertyChange("paintTrack", !paint, paint); } } /** * This method returns whether labels will be painted. * * @return Whether labels will be painted. */ public boolean getPaintLabels() { return paintLabels; } /** * This method changes the "paintLabels" property. * * @param paint Whether labels will be painted. */ public void setPaintLabels(boolean paint) { if (paint != paintLabels) { paintLabels = paint; if (paint && majorTickSpacing > 0) labelTable = createStandardLabels(majorTickSpacing); firePropertyChange("paintLabels", !paint, paint); } } /** * This method is used primarily for debugging purposes and returns a string * that can be used to represent this slider. * * @return A string representing this slider. */ protected String paramString() { return "JSlider"; } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public AccessibleContext getAccessibleContext() { if (accessibleContext == null) accessibleContext = new AccessibleJSlider(); return accessibleContext; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -