Example usage for javax.swing JComponent putClientProperty

List of usage examples for javax.swing JComponent putClientProperty

Introduction

In this page you can find the example usage for javax.swing JComponent putClientProperty.

Prototype

public final void putClientProperty(Object key, Object value) 

Source Link

Document

Adds an arbitrary key/value "client property" to this component.

Usage

From source file:GUI.MainWindow.java

/**
 * @param args the command line arguments
 */// www.j  ava2s.  com
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {

        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>

    // Create right click context menu for most Text Components
    final JPopupMenu copypaste = new JPopupMenu();

    JMenuItem cut = new JMenuItem(new DefaultEditorKit.CutAction());
    cut.setText("Cut");
    copypaste.add(cut);

    JMenuItem copy = new JMenuItem(new DefaultEditorKit.CopyAction());
    copy.setText("Copy");
    copypaste.add(copy);

    JMenuItem paste = new JMenuItem(new DefaultEditorKit.PasteAction());
    paste.setText("Paste");
    copypaste.add(paste);

    // Taken from here. It succinctly added a right click context menu to every text component.
    // http://stackoverflow.com/questions/19424574/adding-a-context-menu-to-all-swing-text-components-in-application
    javax.swing.UIManager.addAuxiliaryLookAndFeel(new LookAndFeel() {
        private final UIDefaults defaults = new UIDefaults() {
            public javax.swing.plaf.ComponentUI getUI(JComponent c) {
                if (c instanceof javax.swing.text.JTextComponent) {
                    if (c.getClientProperty(this) == null) {
                        c.setComponentPopupMenu(copypaste);
                        c.putClientProperty(this, Boolean.TRUE);
                    }
                }
                return null;
            }
        };

        @Override
        public UIDefaults getDefaults() {
            return defaults;
        }

        ;

        @Override
        public String getID() {
            return "TextContextMenu";
        }

        @Override
        public String getName() {
            return getID();
        }

        @Override
        public String getDescription() {
            return getID();
        }

        @Override
        public boolean isNativeLookAndFeel() {
            return false;
        }

        @Override
        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MainWindow().setVisible(true);
        }
    });
}

From source file:Main.java

public static void useAntiAliasing(JComponent component) {
    component.putClientProperty("AATextPropertyKey", true);
}

From source file:Main.java

/**
 * Removes HANDLES_ENABLE_STATE mark from component client properties.
 *
 * @param component component to process
 *//* w w w . j av a 2 s  .c  om*/
public static void removeHandlesEnableStateMark(final JComponent component) {
    component.putClientProperty(HANDLES_ENABLE_STATE, Boolean.FALSE);
}

From source file:Main.java

/**
 * Adds HANDLES_ENABLE_STATE mark into component client properties.
 *
 * @param component//from w w w  .j  a  v a  2  s.  com
 *            component to process
 */
public static void setHandlesEnableStateMark(final JComponent component) {
    component.putClientProperty(HANDLES_ENABLE_STATE, Boolean.TRUE);
}

From source file:Main.java

private static void doPutClientPropertyInEDT(final JComponent jComponent, final Object key,
        final Object value) {
    jComponent.putClientProperty(key, value);
}

From source file:Main.java

/**
 * Sets a component's opaque status/*from  ww w  . j ava 2s.c  om*/
 *
 * @param descriptionField
 * @param b
 */
public static JComponent setOpaque(final JComponent descriptionField, final boolean b) {
    descriptionField.setOpaque(b);
    descriptionField.putClientProperty("Synthetica.opaque", b ? Boolean.TRUE : Boolean.FALSE);
    return descriptionField;
}

From source file:Main.java

public static void putClientProperty(final JComponent jComponent, final Object key, final Object value) {
    if (jComponent != null && key != null) {
        runInEDT(() -> jComponent.putClientProperty(key, value));
    }//w w w .java2  s.c om
}

From source file:Main.java

/**
 * Registers delegate RepaintManager for {@code JComponent}.
 */// www  .  j  a v a 2  s.  c  om
public static void setDelegateRepaintManager(JComponent component, RepaintManager repaintManager) {
    /* setting up flag in AppContext to speed up lookups in case
     * there are no delegate RepaintManagers used.
     */
    AppContext.getAppContext().put(DELEGATE_REPAINT_MANAGER_KEY, Boolean.TRUE);

    component.putClientProperty(DELEGATE_REPAINT_MANAGER_KEY, repaintManager);
}

From source file:com.aw.swing.mvp.view.IPView.java

public static List<JComponent> getCmps(Object target) {
    //        logger.info("searching attributes " + target.getClass().getName());
    List components = new ArrayList();
    List<Field> forms = new ArrayList();
    Class cls = target.getClass();
    Field[] fields = cls.getFields();
    for (int i = 0; i < fields.length; i++) {
        if ((fields[i].getName().startsWith("txt") || fields[i].getName().startsWith("chk"))
                && !fields[i].getName().startsWith("chkSel")) {
            JComponent jComponemt;
            try {
                jComponemt = (JComponent) fields[i].get(target);
                if (jComponemt != null) {
                    jComponemt.putClientProperty("Field", fields[i]);
                    components.add(jComponemt);
                } else {
                    System.out.println("Null:<" + target.getClass() + ">- <" + fields[i].getName() + ">");
                }//from ww  w.  j  a va2 s .  c o  m
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                throw new AWSystemException("Error getting teh value of:<" + fields[i].getName() + ">", e);
            }
        }
        if ((fields[i].getType().getSimpleName().startsWith("Frm"))) {
            forms.add(fields[i]);
        }
    }
    if (forms.size() > 0) {
        for (Field field : forms) {
            try {
                Object formToBeChecked = field.get(target);
                if (formToBeChecked != null) {
                    List formAttributes = getCmps(formToBeChecked);
                    if (formAttributes.size() > 0) {
                        components.addAll(formAttributes);
                    }
                } else {
                    throw new IllegalStateException("FRM NULL:" + field.getName());
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                throw new AWSystemException("Problems getting value for:<" + field.getName() + ">", e);
            }
        }
    }
    return components;
}

From source file:it.unibas.spicygui.controllo.mapping.ActionExportTranslatedInstancesSQL.java

private WizardDescriptor.Panel[] getPanels() {
    panels = new WizardDescriptor.Panel[] { new ExportDBWizardPanel() };
    String[] steps = new String[panels.length];
    for (int i = 0; i < panels.length; i++) {
        Component c = panels[i].getComponent();
        // Default step name to component name of panel. Mainly useful
        // for getting the name of the target chooser to appear in the
        // list of steps.
        steps[i] = c.getName();/*from   w  w w.  jav a 2 s  .  co m*/
        if (c instanceof JComponent) { // assume Swing components
            JComponent jc = (JComponent) c;
            // Sets step number of a component
            jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i));
            // Sets steps names for a panel
            jc.putClientProperty("WizardPanel_contentData", steps);
            // Turn on subtitle creation on each step
            jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
            // Show steps on the left side with the image on the background
            jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
            // Turn on numbering of all steps
            jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
        }
    }
    return panels;
}