Java Code Examples for javax.swing.JComponent.add()

The following are Jave code examples for showing how to use add() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: EditorUI.java   View Source Code Vote up 7 votes
protected JComponent createExtComponent() {
    setLineNumberEnabled(true); // enable line numbering

    // extComponent will be a panel
    JComponent ec = new JPanel(new BorderLayout());
    ec.putClientProperty(JTextComponent.class, component);

    // Add the scroll-pane with the component to the center
    JScrollPane scroller = new JScrollPane(component);
    scroller.getViewport().setMinimumSize(new Dimension(4,4));
    
    // remove default scroll-pane border, winsys will handle borders itself           
    scroller.setBorder(null);
    
    setGlyphGutter(new GlyphGutter(this));
    scroller.setRowHeaderView(glyphGutter);

    initGlyphCorner(scroller);
    
    ec.add(scroller);

    // Install the status-bar panel to the bottom
    ec.add(getStatusBar().getPanel(), BorderLayout.SOUTH);
    
    return ec;
}
 
Example 2
Project: incubator-netbeans   File: ClassBreakpointPanel.java   View Source Code Vote up 6 votes
static Pair<JScrollPane, JEditorPane> addClassNameEditorCC(String mimeType, JComponent comp, String className, String tooltipText) {
    JComponent [] editorComponents = Utilities.createSingleLineEditor(mimeType);
    JScrollPane sle = (JScrollPane) editorComponents[0];
    JEditorPane epClassName = (JEditorPane) editorComponents[1];
    epClassName.setText(className);
    if (comp != null) {
        java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        comp.add(sle, gridBagConstraints);
    }
    sle.setToolTipText(tooltipText);
    epClassName.setToolTipText(tooltipText);
    return Pair.<JScrollPane, JEditorPane>of(sle, epClassName);
}
 
Example 3
Project: incubator-netbeans   File: DefaultPlugin.java   View Source Code Vote up 6 votes
/**
 */
private static JComponent wrapDialogContent(JComponent comp,
                                            boolean selfResizing) {
    JComponent result;
    
    if ((comp.getBorder() != null) || selfResizing) {
        result = selfResizing ? new SelfResizingPanel() : new JPanel();
        result.setLayout(new GridLayout());
        result.add(comp);
    } else {
        result = comp;
    }
    result.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
    result.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_title_select_generator"));
    return result;
}
 
Example 4
Project: incubator-netbeans   File: FilesModifiedConfirmation.java   View Source Code Vote up 6 votes
public FilesModifiedConfirmation(SaveCookie[] saveCookies) {
    btnSaveAll = createSaveAllButton();
    btnSave    = createSaveButton();

    Mnemonics.setLocalizedText(btnSaveAll, getInitialSaveAllButtonText());
    Mnemonics.setLocalizedText(btnSave,    getInitialSaveButtonText());

    JScrollPane scrollPane
            = new JScrollPane(list = createFilesList(saveCookies));

    if (!listModel.isEmpty()) {
        list.setSelectedIndex(0);
    } else {
        updateSaveButtonState();
    }

    JComponent panel = new JPanel(new GridLayout(1, 1));
    panel.add(scrollPane);
    panel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
    mainComponent = panel;
}
 
Example 5
Project: incubator-netbeans   File: DataView.java   View Source Code Vote up 6 votes
public void activateFilter() {
    JComponent panel = getBottomPanel();
    
    if (filterPanel == null) {
        filterPanel = FilterUtils.createFilterPanel(getResultsComponent(), getExcludesFilter(), getFilterOptions());
        panel.add(filterPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }
    
    panel.setVisible(true);
    
    filterPanel.setVisible(true);
    filterPanel.requestFocusInWindow();
}
 
Example 6
Project: incubator-netbeans   File: DataView.java   View Source Code Vote up 6 votes
public void activateSearch() {
    JComponent panel = getBottomPanel();
    
    if (searchPanel == null) {
        SearchUtils.TreeHelper searchHelper = getSearchHelper();
        if (searchHelper == null) searchPanel = SearchUtils.createSearchPanel(getResultsComponent(), getSearchOptions());
        else searchPanel = SearchUtils.createSearchPanel((ProfilerTreeTable)getResultsComponent(), searchHelper, getSearchOptions());
        panel.add(searchPanel);
        Container parent = panel.getParent();
        parent.invalidate();
        parent.revalidate();
        parent.repaint();
    }
    
    panel.setVisible(true);
    
    searchPanel.setVisible(true);
    searchPanel.requestFocusInWindow();
}
 
Example 7
Project: incubator-netbeans   File: GuiUtils.java   View Source Code Vote up 6 votes
/**
 * Creates a labelled group of checkboxes.
 *
 * @param  title  title for the group of checkboxes
 * @param  elements  checkboxes - members of the group
 * @return  visual component representing the group
 */
public static JComponent createChkBoxGroup(String title,
                                           JCheckBox[] elements) {
    
    /* create a component representing the group without title: */
    JComponent content = new JPanel(new GridLayout(0, 1, 0, 5));
    for (int i = 0; i < elements.length; i++) {
        content.add(elements[i]);
    }
    
    /* add the title and insets to the group: */
    JPanel result = new SizeRestrictedPanel(new BorderLayout(), true, true);
    result.add(new JLabel(title), BorderLayout.NORTH);
    addBorder(content, BorderFactory.createEmptyBorder(6, 12, 0, 0));
    result.add(content, BorderLayout.CENTER);
    
    return result;
}
 
Example 8
Project: MaxSim   File: CFGOptionsPanel.java   View Source Code Vote up 6 votes
private void addColorChooser(JComponent c, String displayName, ColorChooser chooser) {
    GridBagLayout layout = (GridBagLayout)c.getLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.insets = new Insets(3, 3, 3, 3);
    constraints.weightx = 0.0;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.EAST;
    JLabel label = new JLabel(displayName, JLabel.TRAILING);
    layout.setConstraints(label, constraints);
    c.add(label);
    constraints.anchor = GridBagConstraints.WEST;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    layout.setConstraints(chooser, constraints);
    c.add(chooser);
    elements.add(chooser);
    label.setLabelFor(chooser);
}
 
Example 9
Project: incubator-netbeans   File: ClassBreakpointPanel.java   View Source Code Vote up 5 votes
static JTextField addClassNameEditor(JComponent comp, String className, String tooltipText) {
    JTextField textField = new JTextField(className); // NOI18N
    java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
    comp.add(textField, gridBagConstraints);
    textField.setToolTipText(tooltipText);
    return textField;
}
 
Example 10
Project: openjdk-jdk10   File: bug4337267.java   View Source Code Vote up 5 votes
void injectComponent(JComponent p, JComponent c, boolean shape) {
    if (shape) {
        setShaping(c);
    }
    p.removeAll();
    p.add(c);
}
 
Example 11
Project: VASSAL-src   File: ServerAddressBook.java   View Source Code Vote up 5 votes
protected void addAdditionalControls(JComponent c, boolean enabled) {
  jabberUser.setEditable(enabled);
  jabberPw.setEditable(enabled);
  c.add(new JLabel(Resources.getString("ServerAddressBook.user_name"))); //$NON-NLS-1$
  c.add(jabberUser, "wrap, grow, push"); //$NON-NLS-1$
  c.add(new JLabel(Resources.getString("ServerAddressBook.password"))); //$NON-NLS-1$
  c.add(jabberPw, "wrap, grow, push"); //$NON-NLS-1$
}
 
Example 12
Project: jdk8u-jdk   File: bug4337267.java   View Source Code Vote up 5 votes
void injectComponent(JComponent p, JComponent c, boolean shape) {
    if (shape) {
        setShaping(c);
    }
    p.removeAll();
    p.add(c);
}
 
Example 13
Project: brModelo   File: Controler.java   View Source Code Vote up 5 votes
public void PopuleBarra(JComponent obj) {
    ButtonGroup buttons = new ButtonGroup();
    Barra = obj;

    Acao ac = new Acao(editor, "?", "Controler.interface.BarraLateral.Nothing.img", "Controler.interface.BarraLateral.Nothing.Texto", null);
    JToggleButton btn = arrume(new JToggleButton(ac));
    buttons.add(btn);
    obj.add(btn);
    btn.setSelected(true);
    ac.IDX = -1;
    this.BtnNothing = btn;
    int i = 0;
    for (ConfigAcao ca : Lista) {
        if (ca.tipo == TipoConfigAcao.tpBotoes || ca.tipo == TipoConfigAcao.tpAny) {
            ac = new Acao(editor, ca.texto, ca.ico, ca.descricao, ca.command);
            ac.IDX = i++;
            btn = arrume(new JToggleButton(ac));
            buttons.add(btn);
            //obj.add(btn);
            listaBotoes.put(ca.command, btn);
        }
    }
    menuComandos c = menuComandos.cmdDel;
    String str = "Controler.comandos." + c.toString().substring(3).toLowerCase();
    ac = new Acao(editor, Editor.fromConfiguracao.getValor(str + ".descricao"), str + ".img", str + ".descricao", c.toString());
    ListaDeAcoesEditaveis.add(ac);
    ac.normal = false;
    JButton btn2 = new JButton(ac);
    btn2.setHideActionText(true);
    btn2.setFocusable(false);
    btn2.setPreferredSize(new Dimension(40, 40));
    obj.add(btn2);

    LayoutManager la = obj.getLayout();
    if (la instanceof GridLayout) {
        ((GridLayout) la).setRows(i + 2);
    }
}
 
Example 14
Project: incubator-netbeans   File: MenuEditLayer.java   View Source Code Vote up 4 votes
private void registerForm(final RADVisualContainer metacomp, final JMenu menu) {
    // don't double register
    if(!formModelListeners.containsKey(metacomp)) {
        FormModelListener fml = new FormModelListener() {
            @Override
            public void formChanged(FormModelEvent[] events) {
                if (events != null) {
                    for(FormModelEvent evt : events) {
                        if(evt.getChangeType() == FormModelEvent.FORM_TO_BE_CLOSED) {
                            formModelListeners.remove(metacomp);
                            metacomp.getFormModel().addFormModelListener(this);
                            continue;
                        }
                        
                        if(evt.getChangeType() == FormModelEvent.COMPONENT_PROPERTY_CHANGED) {
                            if("action".equals(evt.getPropertyName())) { // NOI18N
                                configureEditedComponent(evt.getComponent());
                            }
                        }
                        if(evt.getChangeType() == FormModelEvent.COMPONENT_PROPERTY_CHANGED || evt.getChangeType() == FormModelEvent.BINDING_PROPERTY_CHANGED) {
                            if(evt.getContainer() == metacomp || evt.getComponent() == metacomp) {
                                rebuildOnScreenMenu(metacomp);
                            }
                            updateIcon(evt.getComponent());
                        }
                        
                        if(evt.getChangeType() == FormModelEvent.COMPONENT_ADDED) {
                            updateIcon(evt.getComponent());
                            //reinstall the accelerator preview when moving items around
                            if(evt.getComponent() != null) {
                                Component co = (Component) formDesigner.getComponent(evt.getComponent());
                                if(co instanceof JMenuItem) {
                                    installAcceleratorPreview((JMenuItem)co);
                                }
                            }
                        }
                        
                        // if this menu was deleted then make sure it's popup is hidden and removed
                        if(evt.getChangeType() == FormModelEvent.COMPONENT_REMOVED) {
                            if(evt.getComponent() == metacomp) {
                                unconfigureMenu(menu);
                                continue;
                            }
                        }
                        // if something added to the menu we monitor
                        if(evt.getChangeType() == FormModelEvent.COMPONENT_ADDED ||
                                evt.getChangeType() == FormModelEvent.COMPONENTS_REORDERED ||
                                evt.getChangeType() == FormModelEvent.COMPONENT_REMOVED) {
                            if(evt.getContainer() == metacomp) {
                                // then rebuild the menu
                                rebuildOnScreenMenu(metacomp);
                                return;
                            }
                            if(evt.getContainer() == getFormMenuBar()) {
                                JComponent comp = (JComponent) formDesigner.getComponent(getFormMenuBar());
                                if (comp != null) { // MenuBar not shown in the designer, see issue 124873
                                    RADVisualContainer rad = (RADVisualContainer) getFormMenuBar();
                                    comp.removeAll();
                                    for(RADVisualComponent c : rad.getSubComponents()) {
                                        if(c!=null) {
                                            comp.add((JComponent)formDesigner.getComponent(c));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        };
        formModelListeners.put(metacomp,fml);
        metacomp.getFormModel().addFormModelListener(fml);
    }
}
 
Example 15
Project: xdman   File: XDMMainWindow.java   View Source Code Vote up 4 votes
void addMenuItem(String id, JComponent menu) {
	JMenuItem mitem = new JMenuItem(getString(id));
	mitem.setName(id);
	mitem.addActionListener(this);
	menu.add(mitem);
}
 
Example 16
Project: incubator-netbeans   File: TestSuiteStepLocation.java   View Source Code Vote up 4 votes
private Component createVisualComp() {
    JCheckBox[] chkBoxes;
    
    JComponent infoLabel = GuiUtils.createMultilineLabel(
            NbBundle.getMessage(TestSuiteStepLocation.class,
                                "TXT_ClassesInSuite"));             //NOI18N
    JComponent optCode = GuiUtils.createChkBoxGroup(
            NbBundle.getMessage(
                    GuiUtils.class,
                    "CommonTestsCfgOfCreate.groupOptCode"),               //NOI18N
            chkBoxes = GuiUtils.createCheckBoxes(new String[] {
                    GuiUtils.CHK_SETUP,
                    GuiUtils.CHK_TEARDOWN,
                    GuiUtils.CHK_BEFORE_CLASS,
                    GuiUtils.CHK_AFTER_CLASS}));
    chkSetUp = chkBoxes[0];
    chkTearDown = chkBoxes[1];
    chkBeforeClass = chkBoxes[2];
    chkAfterClass = chkBoxes[3];
    
    JComponent optComments = GuiUtils.createChkBoxGroup(
            NbBundle.getMessage(
                    GuiUtils.class,
                    "CommonTestsCfgOfCreate.groupOptComments"),           //NOI18N
            chkBoxes = GuiUtils.createCheckBoxes(new String[] {
                    GuiUtils.CHK_HINTS}));
    chkCodeHints = chkBoxes[0];

    JComponent bottomPanel = new SelfResizingPanel();
    bottomPanel.setLayout(new BorderLayout(0, 24));
    bottomPanel.add(infoLabel, BorderLayout.NORTH);
    JComponent box = new JPanel();
    box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
    box.add(optCode);
    box.add(Box.createHorizontalStrut(18));
    box.add(optComments);
    bottomPanel.add(box, BorderLayout.CENTER);
    
    /* tune layout of the components within the box: */
    infoLabel.setAlignmentX(0.0f);
    optCode.setAlignmentY(0.0f);
    optComments.setAlignmentY(0.0f);
 
    return bottomPanel;
}
 
Example 17
Project: incubator-netbeans   File: NbEditorUI.java   View Source Code Vote up 4 votes
@Override
    protected JComponent createExtComponent() {

        JTextComponent component = getComponent();
        
        JLayeredPane layers = new LayeredEditorPane(component);
        layers.add(component, JLayeredPane.DEFAULT_LAYER, 0);
//        MyInternalFrame window = new MyInternalFrame();
//        layers.add(window, JLayeredPane.PALETTE_LAYER);
//        window.show();

        // Add the scroll-pane with the component to the center
        JScrollPane scroller = new JScrollPane(layers);
        scroller.getViewport().setMinimumSize(new Dimension(4,4));

        // remove default scroll-pane border, winsys will handle borders itself 
        Border empty = BorderFactory.createEmptyBorder();
        // Important:  Do not delete or use null instead, will cause
        //problems on GTK L&F.  Must set both scroller border & viewport
        //border! - Tim
        scroller.setBorder(empty);
        scroller.setViewportBorder(empty);
        
        if (component.getClientProperty("nbeditorui.vScrollPolicy") != null) {
            scroller.setVerticalScrollBarPolicy(
                    (Integer)component.getClientProperty("nbeditorui.vScrollPolicy"));
        }
        if (component.getClientProperty("nbeditorui.hScrollPolicy") != null) {
            scroller.setHorizontalScrollBarPolicy(
                    (Integer)component.getClientProperty("nbeditorui.hScrollPolicy"));
        }
        // extComponent will be a panel
        JComponent ec = new JPanel(new BorderLayout());
        ec.putClientProperty(JTextComponent.class, component);
        ec.add(scroller);

        // Initialize sidebars
        // Need to clear the cache - it's null at this point when opening file but the sidebars
        // would be reused during L&F change (see BaseTextUI.UIWatcher) which would not work properly.
        CustomizableSideBar.resetSideBars(component);
        Map<SideBarPosition, JComponent> sideBars = CustomizableSideBar.getSideBars(component);
        processSideBars(sideBars, ec, scroller);
        
        if (listener == null){
            listener = new SideBarsListener(component);
            CustomizableSideBar.addChangeListener(NbEditorUtilities.getMimeType(component), listener);
        }
        
        // Initialize the corner component
        initGlyphCorner(scroller);

        return ec;
    }
 
Example 18
Project: Tarski   File: OurTabbedSyntaxWidget.java   View Source Code Vote up 4 votes
/** Add this object into the given container. */
public void addTo(JComponent newParent, Object constraint) { newParent.add(component, constraint); }
 
Example 19
Project: Tarski   File: OurSyntaxWidget.java   View Source Code Vote up 4 votes
/** Add this object into the given container. */
public void addTo(JComponent newParent, Object constraint) { newParent.add(component, constraint); }
 
Example 20
Project: org.alloytools.alloy   File: OurTabbedSyntaxWidget.java   View Source Code Vote up 4 votes
/** Add this object into the given container. */
public void addTo(JComponent newParent, Object constraint) {
	newParent.add(component, constraint);
}