當前位置: 首頁>>代碼示例>>Java>>正文


Java JSpinner.getEditor方法代碼示例

本文整理匯總了Java中javax.swing.JSpinner.getEditor方法的典型用法代碼示例。如果您正苦於以下問題:Java JSpinner.getEditor方法的具體用法?Java JSpinner.getEditor怎麽用?Java JSpinner.getEditor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.JSpinner的用法示例。


在下文中一共展示了JSpinner.getEditor方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCalendarField

import javax.swing.JSpinner; //導入方法依賴的package包/類
/**
 * Returns the calendarField under the start of the selection, or -1 if
 * there is no valid calendar field under the selection (or the spinner
 * isn't editing dates.
 */
private int getCalendarField(JSpinner spinner)
{
	JComponent editor = spinner.getEditor();

	if( editor instanceof JSpinner.DateEditor )
	{
		JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
		JFormattedTextField ftf = dateEditor.getTextField();
		int start = ftf.getSelectionStart();
		JFormattedTextField.AbstractFormatter formatter = ftf.getFormatter();

		if( formatter instanceof InternationalFormatter )
		{
			Format.Field[] fields = ((InternationalFormatter) formatter).getFields(start);

			for( int counter = 0; counter < fields.length; counter++ )
			{
				if( fields[counter] instanceof DateFormat.Field )
				{
					int calendarField;

					if( fields[counter] == DateFormat.Field.HOUR1 )
					{
						calendarField = Calendar.HOUR;
					}
					else
					{
						calendarField = ((DateFormat.Field) fields[counter]).getCalendarField();
					}
					if( calendarField != -1 )
					{
						return calendarField;
					}
				}
			}
		}
	}
	return -1;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:45,代碼來源:FlatterSpinnerUI.java

示例2: testDefaultFont

import javax.swing.JSpinner; //導入方法依賴的package包/類
private static void testDefaultFont(final JFrame frame) {
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSpinner spinner = new JSpinner();
    frame.add(spinner);
    frame.setSize(300, 100);
    frame.setVisible(true);

    final DefaultEditor editor = (DefaultEditor) spinner.getEditor();
    final Font editorFont = editor.getTextField().getFont();

    /*
     * 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.
     */

    if (!(editorFont instanceof UIResource)) {
        throw new RuntimeException("Font must be UIResource");
    }
    if (!editorFont.equals(spinner.getFont())) {
        throw new RuntimeException("Wrong FONT");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:bug6421058.java

示例3: select

import javax.swing.JSpinner; //導入方法依賴的package包/類
/**
 * If the spinner's editor is a DateEditor, this selects the field
 * associated with the value that is being incremented.
 */
private void select(JSpinner spinner)
{
	JComponent editor = spinner.getEditor();

	if( editor instanceof JSpinner.DateEditor )
	{
		JSpinner.DateEditor dateEditor = (JSpinner.DateEditor) editor;
		JFormattedTextField ftf = dateEditor.getTextField();
		Format format = dateEditor.getFormat();
		Object value = spinner.getValue();

		if( format != null && value != null )
		{
			SpinnerDateModel model = dateEditor.getModel();
			DateFormat.Field field = DateFormat.Field.ofCalendarField(model.getCalendarField());

			if( field != null )
			{
				try
				{
					AttributedCharacterIterator iterator = format.formatToCharacterIterator(value);
					if( !select(ftf, iterator, field) && field == DateFormat.Field.HOUR0 )
					{
						select(ftf, iterator, DateFormat.Field.HOUR1);
					}
				}
				catch( IllegalArgumentException iae )
				{
					// ??
				}
			}
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:39,代碼來源:FlatterSpinnerUI.java

示例4: testDefaultFont

import javax.swing.JSpinner; //導入方法依賴的package包/類
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));
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:42,代碼來源:WrongEditorTextFieldFont.java


注:本文中的javax.swing.JSpinner.getEditor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。