本文整理匯總了Java中javax.swing.JSlider.HORIZONTAL屬性的典型用法代碼示例。如果您正苦於以下問題:Java JSlider.HORIZONTAL屬性的具體用法?Java JSlider.HORIZONTAL怎麽用?Java JSlider.HORIZONTAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.swing.JSlider
的用法示例。
在下文中一共展示了JSlider.HORIZONTAL屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getControls
public Component getControls() {
final JSlider slider = new JSlider(JSlider.HORIZONTAL,0,100,opacity);
final HashMap<Integer,JLabel> labelTable = new HashMap<Integer,JLabel>();
labelTable.put(0, new JLabel("Transparent"));
labelTable.put(100, new JLabel("Opaque"));
slider.setMajorTickSpacing(10);
slider.setPaintTicks(true);
// Note: JSlider uses the outdated Hashtable. Eventually Hashtable
// will be deprecated and we'll be able to use the HashMap directly.
slider.setLabelTable(new Hashtable<Integer,JLabel>(labelTable));
slider.setPaintLabels(true);
slider.setBorder(javax.swing.BorderFactory.createTitledBorder(name));
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
final JSlider source = (JSlider) e.getSource();
if (!source.getValueIsAdjusting()) {
opacity = source.getValue();
}
}});
return slider;
}
示例2: DrivestrengthMainWindow
public DrivestrengthMainWindow() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
setLayout(new GridBagLayout());
setTitle("ASGDrivestrength");
setSize(500, 300);
JSlider percentageEnergySlider = new JSlider(JSlider.HORIZONTAL,
0, 100, 0);
JButton runButton = new JButton("Run");
add(percentageEnergySlider);
add(runButton);
setVisible(true);
}
示例3: getThumbSize
protected Dimension getThumbSize() {
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
return new Dimension( 30, 15 );
}
else {
return new Dimension( 15, 30 );
}
}
示例4: getClickPoint
private Point getClickPoint(ComponentOperator oper, int direction, int orientation) {
int x, y;
boolean inverted = ((JSliderOperator) oper).getInverted();
int realDirection = ScrollAdjuster.DO_NOT_TOUCH_SCROLL_DIRECTION;
if (inverted) {
if (direction == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
realDirection = ScrollAdjuster.DECREASE_SCROLL_DIRECTION;
} else if (direction == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
realDirection = ScrollAdjuster.INCREASE_SCROLL_DIRECTION;
} else {
return null;
}
} else {
realDirection = direction;
}
if (orientation == JSlider.HORIZONTAL) {
if (realDirection == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
x = oper.getWidth() - 1;
} else if (realDirection == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
x = 0;
} else {
return null;
}
y = oper.getHeight() / 2;
} else if (orientation == JSlider.VERTICAL) {
if (realDirection == ScrollAdjuster.INCREASE_SCROLL_DIRECTION) {
y = 0;
} else if (realDirection == ScrollAdjuster.DECREASE_SCROLL_DIRECTION) {
y = oper.getHeight() - 1;
} else {
return null;
}
x = oper.getWidth() / 2;
} else {
return null;
}
return new Point(x, y);
}
示例5: createFilterPanel
/**
* @return
*/
private Component createFilterPanel() {
JPanel jp = new MyJPanel("Filter nodes", Color.RED);
jp.add(new JLabel("Betweenness:"));
mNodeAcceptBetweennessSlider = new JSlider(JSlider.HORIZONTAL);
mNodeAcceptBetweennessSlider.setPreferredSize(new Dimension(180, 40));
mNodeAcceptBetweennessSlider.setValue(0);
mNodeAcceptBetweennessSlider.setPaintTicks(true);
mNodeAcceptBetweennessSlider.setBackground(Color.WHITE);
jp.add(mNodeAcceptBetweennessSlider);
return jp;
}
示例6: createAnimationControls
private void createAnimationControls() {
Font sliderFont = new Font("Arial", Font.PLAIN, 12);
animationControls = new JPanel();
animationControls.setLayout(new BoxLayout(animationControls,
BoxLayout.PAGE_AXIS));
JLabel manualLabel = new JLabel("Frame #");
manualLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
manualSlider = new JSlider(JSlider.HORIZONTAL);
manualSlider.setPaintTicks(true);
manualSlider.setPaintLabels(true);
manualSlider.setFont(sliderFont);
manualSlider.addChangeListener(manualSliderListener);
manualSlider.addMouseListener(manualSliderClickListener);
manualSlider.setMinorTickSpacing(1);
manualSlider.addComponentListener(resizeListener);
JLabel framerateLabel = new JLabel("Framerate");
framerateLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
framerateSlider = new JSlider(JSlider.HORIZONTAL, FRAMERATE_MIN,
FRAMERATE_MAX, FRAMERATE_INIT);
framerateSlider.setMajorTickSpacing(10);
framerateSlider.setMinorTickSpacing(1);
framerateSlider.setPaintTicks(true);
framerateSlider.setPaintLabels(true);
framerateSlider.setLabelTable(framerateSlider.createStandardLabels(10,
10));
framerateSlider.setFont(sliderFont);
framerateSlider.addChangeListener(framerateListener);
JPanel frameratePanel = new JPanel();
frameratePanel.setLayout(new BoxLayout(frameratePanel,
BoxLayout.PAGE_AXIS));
frameratePanel.add(framerateLabel);
frameratePanel.add(Box.createRigidArea(new Dimension(0, 2)));
frameratePanel.add(framerateSlider);
playPauseButton = new JButton(playIcon);
playPauseButton.addActionListener(playPauseListener);
stopButton = new JButton(stopIcon);
stopButton.addActionListener(stopListener);
animationControls.add(new JSeparator(JSeparator.HORIZONTAL));
animationControls.add(Box.createRigidArea(new Dimension(0, 2)));
animationControls.add(manualLabel);
animationControls.add(Box.createRigidArea(new Dimension(0, 2)));
animationControls.add(manualSlider);
animationControls.add(Box.createRigidArea(new Dimension(0, 5)));
JPanel p2 = new JPanel();
p2.setLayout(new BoxLayout(p2, BoxLayout.LINE_AXIS));
p2.add(playPauseButton);
p2.add(Box.createRigidArea(new Dimension(10, 0)));
p2.add(stopButton);
p2.add(frameratePanel);
animationControls.add(p2);
animationControls.setVisible(false);
animationControls.setBorder(BorderFactory.createEmptyBorder(0, 10, 5,
10));
container.add(animationControls, BorderLayout.SOUTH);
}
示例7: getUI
@Override
public JComponent getUI() {
JSlider slider = new JSlider( JSlider.HORIZONTAL, -1, gNode.getChildren().size(), -1 );
slider.addChangeListener( new ChangeListener() {
@Override
public void stateChanged( ChangeEvent e ) {
tweed.enqueue( new Runnable() {
@Override
public void run() {
int value = slider.getValue();
for ( Spatial s : gNode.getChildren() ) {
if ( s instanceof Node ) {
Integer i = s.getUserData( ProfileGen.class.getSimpleName() );
if ( i != null && s instanceof Node )
if ( value == -1 || i == value )
s.setCullHint( CullHint.Inherit );
else
s.setCullHint( CullHint.Always );
}
}
tweed.gainFocus();
}
} );
}
} );
JButton skel = new JButton("optimize");
skel.addActionListener( ae -> doSkel() );
JComboBox<Mode> vizMode = new JComboBox<>(Mode.values());
vizMode.addActionListener(e -> doViz( (Mode) vizMode.getSelectedItem() ) );
JButton writeProfiles = new JButton("dump profs");
writeProfiles.addActionListener( ae -> writeProfiles() );
JButton stateBuilder = new JButton("segmenter ui");
stateBuilder.addActionListener( ae -> new SSBuilder(this, tweed.features) );
JPanel out = new JPanel( new ListDownLayout() );
out.add( new JLabel("profiles rendered:") );
out.add( slider );
out.add( skel );
out.add( new JLabel("viz:") );
out.add( vizMode );
out.add( writeProfiles );
out.add( stateBuilder );
return out;
}
示例8: paintThumb
public void paintThumb(Graphics g) {
Rectangle knobBounds = thumbRect;
int x = knobBounds.x;
int y = knobBounds.y;
int w = knobBounds.width;
int h = knobBounds.height;
if ( slider.isEnabled() ) {
g.setColor(slider.getForeground());
}
else {
// PENDING(jeff) - the thumb should be dithered when disabled
g.setColor(slider.getForeground().darker());
}
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
g.translate(x, knobBounds.y-1);
// fill
g.fillRect(0, 1, w, h - 1);
// highlight
g.setColor(getHighlightColor());
drawHLine(g, 0, w - 1, 1); // top
drawVLine(g, 0, 1, h); // left
drawVLine(g, w / 2, 2, h - 1); // center
// shadow
g.setColor(getShadowColor());
drawHLine(g, 0, w - 1, h); // bottom
drawVLine(g, w - 1, 1, h); // right
drawVLine(g, w / 2 - 1, 2, h); // center
g.translate(-x, -(knobBounds.y-1));
}
else {
g.translate(knobBounds.x-1, 0);
// fill
g.fillRect(1, y, w - 1, h);
// highlight
g.setColor(getHighlightColor());
drawHLine(g, 1, w, y); // top
drawVLine(g, 1, y + 1, y + h - 1); // left
drawHLine(g, 2, w - 1, y + h / 2); // center
// shadow
g.setColor(getShadowColor());
drawHLine(g, 2, w, y + h - 1); // bottom
drawVLine(g, w, y + h - 1, y); // right
drawHLine(g, 2, w - 1, y + h / 2 - 1);// center
g.translate(-(knobBounds.x-1), 0);
}
}
示例9: editProfile
public FanSpeedProfile editProfile(FanSpeedProfile profile) {
JPanel panel = new JPanel(), sliderPanel = new JPanel(), weightPanel = new JPanel();
JSlider[] sliders;
JSlider weightSlider = new JSlider(JSlider.HORIZONTAL, 0, 100, 50);
JTextField nameField = new JTextField(20);
if (profile != null) {
nameField.setText(profile.getName());
sliders = Arrays.stream(profile.getPercentages()).mapToObj(i -> new JSlider(JSlider.VERTICAL, 0, 100, i))
.toArray(JSlider[]::new);
weightSlider.setValue(profile.getCpuWeight());
} else {
sliders = IntStream.range(0, FanSpeedProfile.STEPS).mapToObj(i -> new JSlider(JSlider.VERTICAL, 0, 100, 50))
.toArray(JSlider[]::new);
}
sliderPanel.setLayout(new GridLayout(1, sliders.length));
sliders[sliders.length -1].setPaintLabels(true);
for (int i = 0; i < sliders.length; i++) {
JSlider s = sliders[i];
s.setPaintTicks(true);
s.setSnapToTicks(true);
s.setLabelTable(dictionary);
s.setMinorTickSpacing(5);
s.setMajorTickSpacing(50);
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.add(s);
p.add(new JLabel(FanSpeedProfile.MIN_TEMP + FanSpeedProfile.STEP_SIZE * i + " \u00B0C"));
sliderPanel.add(p);
}
panel.setLayout(new BorderLayout());
panel.add(GridControlPanel.labelledComponent("Profile name: ", nameField), BorderLayout.NORTH);
panel.add(sliderPanel, BorderLayout.CENTER);
weightPanel.add(new JLabel("GPU"));
weightSlider.setMajorTickSpacing(50);
weightSlider.setMinorTickSpacing(10);
weightSlider.setPaintTicks(true);
weightPanel.add(weightSlider);
weightPanel.add(new JLabel("CPU"));
panel.add(weightPanel, BorderLayout.SOUTH);
int response = JOptionPane.showConfirmDialog(null, panel, "Fan Speed Profile Editor",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (response == JOptionPane.OK_OPTION) {
int[] percs = Arrays.stream(sliders).mapToInt(JSlider::getValue).toArray();
if (profile == null)
profile = new FanSpeedProfile(nameField.getText(), percs, weightSlider.getValue());
else {
profile.setPercentages(percs);
profile.setName(nameField.getText());
profile.setCpuWeight(weightSlider.getValue());
}
if (nameField.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "Please enter a name for the profile.");
return editProfile(profile);
}
return profile;
} else {
return profile;
}
}
示例10: createSizePanel
/**
* @return
*/
private Component createSizePanel() {
final ButtonGroup buttons = new ButtonGroup();
JPanel jp = new MyJPanel("Node Size", Color.RED);
mNodeSizeDegreeSlider = new JSlider(JSlider.HORIZONTAL);
mNodeSizeDegreeSlider.setPreferredSize(new Dimension(180, 40));
mNodeSizeDegreeSlider.setPaintTicks(true);
mNodeSizeDegreeSlider.setBackground(Color.WHITE);
mNodeSizeDegreeSlider.setValue(0);
final JRadioButton degree = new JRadioButton("Degree");
degree.setBackground(Color.WHITE);
degree.setSelected(true);
buttons.add(degree);
jp.add( degree );
jp.add(mNodeSizeDegreeSlider);
mNodeSizePageRankSlider = new JSlider(JSlider.HORIZONTAL);
mNodeSizePageRankSlider.setPreferredSize(new Dimension(180, 40));
mNodeSizePageRankSlider.setPaintTicks(true);
mNodeSizePageRankSlider.setBackground(Color.WHITE);
mNodeSizePageRankSlider.setEnabled( false );
final JRadioButton rank = new JRadioButton("PageRank with Prior");
rank.setBackground(Color.WHITE);
buttons.add(rank);
jp.add( rank );
jp.add( mNodeSizePageRankSlider);
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if( e.getSource() == rank) {
mNodeSizePageRankSlider.setEnabled(true);
mNodeSizeDegreeSlider.setEnabled(false);
}
if ( e.getSource() == degree) {
mNodeSizePageRankSlider.setEnabled(false);
mNodeSizeDegreeSlider.setEnabled(true);
}
}
};
degree.addActionListener(al);
rank.addActionListener(al);
return jp;
}