Java Code Examples for javax.swing.JSlider#setBorder()

The following examples show how to use javax.swing.JSlider#setBorder() . 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: MaterialSliderUI.java    From material-ui-swing with MIT License 5 votes vote down vote up
@Override
public void installUI (JComponent c) {
	super.installUI (c);

	JSlider slider = (JSlider) c;
	slider.setFont (UIManager.getFont ("Slider.font"));
	slider.setBackground (UIManager.getColor ("Slider.background"));
	slider.setForeground (UIManager.getColor ("Slider.foreground"));
	slider.setBorder (UIManager.getBorder ("Slider.border"));
	c.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
 
Example 2
Source File: AnimationController.java    From pumpernickel with MIT License 4 votes vote down vote up
/**
 * Format animation controls and add them to a container. This includes
 * assigning the borders of all the components, assigning the PanelUI of the
 * container, assigning the preferred size of the container, and making a
 * spacebar on the slider trigger the toggle play button.
 * 
 * @param container
 *            this container is emptied, assigned a GridBagLayout, and the
 *            other arguments are added to this container.
 * @param togglePlayButton
 *            this button will be the left-most button. It is expected to
 *            always be visible.
 * @param buttons
 *            an optional collection of buttons to display after the
 *            togglePlayButton.
 * @param slider
 *            the slider that stretches to fill the remaining width.
 */
public static void format(JPanel container, final JButton togglePlayButton,
		JButton[] buttons, JSlider slider) {
	if (buttons == null)
		buttons = new JButton[] {};
	container.setUI(new GradientPanelUI(new Color(0xebebeb), Color.white));
	container.removeAll();
	container.setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.gridx = 0;
	c.gridy = 0;
	c.weightx = 0;
	c.weighty = 1;
	c.fill = GridBagConstraints.VERTICAL;
	container.add(togglePlayButton, c);
	for (int a = 0; a < buttons.length; a++) {
		c.gridx++;
		container.add(buttons[a], c);
		buttons[a].setOpaque(false);
		buttons[a].setContentAreaFilled(false);
		buttons[a].setRolloverIcon(new DarkenedIcon(buttons[a], .5f));
		buttons[a].setPressedIcon(new DarkenedIcon(buttons[a], .75f));
		buttons[a].setBorder(new PartialLineBorder(Color.gray, new Insets(
				1, 0, 1, 1)));
	}
	c.weightx = 1;
	c.gridx++;
	c.fill = GridBagConstraints.BOTH;
	container.add(slider, c);

	togglePlayButton.setOpaque(false);
	togglePlayButton.setContentAreaFilled(false);
	togglePlayButton.setBorder(new LineBorder(Color.gray));
	slider.setOpaque(false);
	slider.setBorder(new PartialLineBorder(Color.gray, new Insets(1, 0, 1,
			1)));
	Dimension d = slider.getPreferredSize();
	d.width = 60;
	d.height = 25;
	slider.setPreferredSize((Dimension) d.clone());
	d.width = d.height;
	togglePlayButton.setPreferredSize(d);
	for (int a = 0; a < buttons.length; a++) {
		buttons[a].setPreferredSize(d);
	}

	InputMap inputMap = slider.getInputMap(JComponent.WHEN_FOCUSED);
	inputMap.put(KeyStroke.getKeyStroke(' '), "togglePlay");
	slider.getActionMap().put("togglePlay", new AbstractAction() {
		private static final long serialVersionUID = 1L;

		public void actionPerformed(ActionEvent e) {
			togglePlayButton.doClick();
		}
	});

	togglePlayButton.setFocusPainted(false);
	setInsetFocusBorder(togglePlayButton);
	for (JButton button : buttons) {
		button.setFocusPainted(false);
		setInsetFocusBorder(button);
	}
	setInsetFocusBorder(slider);
}