Java Code Examples for javax.swing.JSpinner#setFont()

The following examples show how to use javax.swing.JSpinner#setFont() . 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: JPlagCreator.java    From jplag with GNU General Public License v3.0 5 votes vote down vote up
public static JSpinner createSpinner(int width, int height, String toolTip) {
	SpinnerNumberModel model = new SpinnerNumberModel(1, 1, 100, 1);
	JSpinner spinner = new JSpinner(model);
	spinner.setFont(JPlagCreator.SYSTEM_FONT);
	spinner.setPreferredSize(new java.awt.Dimension(width, height));
	spinner.setEnabled(true);
	spinner.setBackground(java.awt.Color.WHITE);
	if (toolTip != null && !toolTip.equals(""))
		((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().setToolTipText(toolTip);
	return spinner;
}
 
Example 2
Source File: WrongEditorTextFieldFont.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static void testDefaultFont(final JFrame frame) {
    final JSpinner spinner = new JSpinner();
    final JSpinner spinner_u = new JSpinner();
    frame.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 50));
    frame.getContentPane().add(spinner);
    frame.getContentPane().add(spinner_u);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    final DefaultEditor ed = (DefaultEditor) spinner.getEditor();
    final DefaultEditor ed_u = (DefaultEditor) spinner_u.getEditor();
    ed_u.getTextField().setFont(USERS_FONT);

    for (int i = 5; i < 40; i += 5) {
        /*
         * Validate that the font of the text field is changed to the
         * font of JSpinner if the font of text field was not set by the
         * user.
         */
        final Font tff = ed.getTextField().getFont();
        if (!(tff instanceof UIResource)) {
            throw new RuntimeException("Font must be UIResource");
        }
        if (spinner.getFont().getSize() != tff.getSize()) {
            throw new RuntimeException("Rrong size");
        }
        spinner.setFont(new Font("dialog", Font.BOLD, i));
        /*
         * Validate that the font of the text field is NOT changed to the
         * font of JSpinner if the font of text field was set by the user.
         */
        final Font tff_u = ed_u.getTextField().getFont();
        if (tff_u instanceof UIResource || !tff_u.equals(USERS_FONT)) {
            throw new RuntimeException("Font must NOT be UIResource");
        }
        if (spinner_u.getFont().getSize() == tff_u.getSize()) {
            throw new RuntimeException("Wrong size");
        }
        spinner_u.setFont(new Font("dialog", Font.BOLD, i));
    }
}
 
Example 3
Source File: DeskewTransformSettingsPanel.java    From swingsane with Apache License 2.0 4 votes vote down vote up
private void initComponents() {
  GridBagLayout gridBagLayout = new GridBagLayout();
  gridBagLayout.columnWidths = new int[] { 32, 0 };
  gridBagLayout.rowHeights = new int[] { 24, 0 };
  gridBagLayout.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
  gridBagLayout.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
  setLayout(gridBagLayout);

  JPanel containerPanel = new JPanel();
  containerPanel.setBorder(new CompoundBorder(new TitledBorder(Localizer
      .localize("DeskewSettingsBorderTitle")), new EmptyBorder(5, 5, 5, 5)));
  GridBagConstraints gbc_containerPanel = new GridBagConstraints();
  gbc_containerPanel.fill = GridBagConstraints.HORIZONTAL;
  gbc_containerPanel.anchor = GridBagConstraints.NORTH;
  gbc_containerPanel.gridx = 0;
  gbc_containerPanel.gridy = 0;
  add(containerPanel, gbc_containerPanel);
  GridBagLayout gbl_containerPanel = new GridBagLayout();
  gbl_containerPanel.columnWidths = new int[] { 0, 0, 0 };
  gbl_containerPanel.rowHeights = new int[] { 24, 0 };
  gbl_containerPanel.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE };
  gbl_containerPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
  containerPanel.setLayout(gbl_containerPanel);

  JLabel deskewThresholdLabel = new JLabel(Localizer.localize("DeskewThresholdLabelText"));
  deskewThresholdLabel.setFont(UIManager.getFont("Label.font"));
  GridBagConstraints gbc_deskewThresholdLabel = new GridBagConstraints();
  gbc_deskewThresholdLabel.insets = new Insets(0, 0, 0, 5);
  gbc_deskewThresholdLabel.anchor = GridBagConstraints.EAST;
  gbc_deskewThresholdLabel.gridx = 0;
  gbc_deskewThresholdLabel.gridy = 0;
  containerPanel.add(deskewThresholdLabel, gbc_deskewThresholdLabel);

  deskewThresholdSpinner = new JSpinner();
  deskewThresholdSpinner.addChangeListener(new ChangeListener() {
    @Override
    public void stateChanged(ChangeEvent e) {
      deskewThresholdStateChanged(e);
    }
  });
  deskewThresholdSpinner.setModel(new SpinnerNumberModel(2.0d, 0.0d, 180.0d, 0.1d));
  deskewThresholdSpinner.setFont(UIManager.getFont("Spinner.font"));
  GridBagConstraints gbc_deskewThresholdSpinner = new GridBagConstraints();
  gbc_deskewThresholdSpinner.anchor = GridBagConstraints.WEST;
  gbc_deskewThresholdSpinner.gridx = 1;
  gbc_deskewThresholdSpinner.gridy = 0;
  containerPanel.add(deskewThresholdSpinner, gbc_deskewThresholdSpinner);
}
 
Example 4
Source File: BinarizeTransformSettingsPanel.java    From swingsane with Apache License 2.0 4 votes vote down vote up
private void initComponents() {
  GridBagLayout gridBagLayout = new GridBagLayout();
  gridBagLayout.columnWidths = new int[] { 32, 0 };
  gridBagLayout.rowHeights = new int[] { 24, 0 };
  gridBagLayout.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
  gridBagLayout.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
  setLayout(gridBagLayout);

  JPanel containerPanel = new JPanel();
  containerPanel.setBorder(new CompoundBorder(new TitledBorder(Localizer
      .localize("LuminanceSettingsBorderTitle")), new EmptyBorder(5, 5, 5, 5)));
  GridBagConstraints gbc_containerPanel = new GridBagConstraints();
  gbc_containerPanel.fill = GridBagConstraints.HORIZONTAL;
  gbc_containerPanel.anchor = GridBagConstraints.NORTH;
  gbc_containerPanel.gridx = 0;
  gbc_containerPanel.gridy = 0;
  add(containerPanel, gbc_containerPanel);
  GridBagLayout gbl_containerPanel = new GridBagLayout();
  gbl_containerPanel.columnWidths = new int[] { 0, 0, 0 };
  gbl_containerPanel.rowHeights = new int[] { 24, 0 };
  gbl_containerPanel.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE };
  gbl_containerPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
  containerPanel.setLayout(gbl_containerPanel);

  JLabel luminanceLabel = new JLabel(Localizer.localize("LuminanceThresholdLabelText"));
  luminanceLabel.setFont(UIManager.getFont("Label.font"));
  GridBagConstraints gbc_luminanceLabel = new GridBagConstraints();
  gbc_luminanceLabel.insets = new Insets(0, 0, 0, 5);
  gbc_luminanceLabel.anchor = GridBagConstraints.EAST;
  gbc_luminanceLabel.gridx = 0;
  gbc_luminanceLabel.gridy = 0;
  containerPanel.add(luminanceLabel, gbc_luminanceLabel);

  luminanceSpinner = new JSpinner();
  luminanceSpinner.addChangeListener(new ChangeListener() {
    @Override
    public void stateChanged(ChangeEvent e) {
      luminanceStateChanged(e);
    }
  });
  luminanceSpinner.setModel(new SpinnerNumberModel(165, 0, 255, 1));
  luminanceSpinner.setFont(UIManager.getFont("Spinner.font"));
  GridBagConstraints gbc_luminanceSpinner = new GridBagConstraints();
  gbc_luminanceSpinner.anchor = GridBagConstraints.WEST;
  gbc_luminanceSpinner.gridx = 1;
  gbc_luminanceSpinner.gridy = 0;
  containerPanel.add(luminanceSpinner, gbc_luminanceSpinner);
}