Example usage for javax.swing JComponent add

List of usage examples for javax.swing JComponent add

Introduction

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

Prototype

public Component add(String name, Component comp) 

Source Link

Document

Adds the specified component to this container.

Usage

From source file:Main.java

public static JPasswordField addLabeledPwdField(JComponent c, String label, int length, boolean wrap) {
    JLabel l = new JLabel(label);
    c.add(l, "align left");

    JPasswordField pwd = new JPasswordField(length);
    if (wrap) {//from  www  .j av  a 2  s  .  co  m
        c.add(pwd, "align left, wrap");
    } else {
        c.add(pwd, "align left");
    }

    return pwd;
}

From source file:Main.java

/** 
 * Adds a <code>JTextField</code> with the specified text as a label
 * appearing before the text field to the given <code>JComponent</code>. 
 * Assuming the <code>JComponent</code> has the MigLayout set, the label
 * and text field are both left aligned within the <code>JComponent</code>.
 * If the wrap parameter is set to true, MigLayout's "wrap" attribute will be
 * applied to the <code>JTextField</code>, meaning the next component added
 * will appear on the next line./*from ww w. jav a2 s.  c  o  m*/
 * (Exception: Will not work if MigLayout's flowy layout constraint is applied,
 * but it is rarely used MigLayout feature and thus not a common concern; however
 * if you have set this layout constraint on your <code>JComponent</code> do not
 * attempt to use the wrap option of this method.)
 * @param label - the text to appear in front of the text field
 * @param length - the length in columns of the text field 
 * @param wrap - indicates is this component should be the last on the current line
 * @return the <code>JTextField</code> added to the component
 */
public static JTextField addLabeledTextField(JComponent c, String label, int length, boolean wrap) {
    JLabel l = new JLabel(label);
    c.add(l, "align left");

    JTextField text = new JTextField(length);
    if (wrap) {
        c.add(text, "align left, wrap");
    } else {
        c.add(text, "align left");
    }

    return text;
}

From source file:Main.java

/** 
 * Adds a <code>JTextArea</code> with the specified text as a label
 * appearing before the text field to the given <code>JComponent</code>. 
 * Assuming the <code>JComponent</code> has the MigLayout set, the label
 * and text field are both left aligned within the <code>JComponent</code>.
 * If the wrap parameter is set to true, MigLayout's "wrap" attribute will be
 * applied to the <code>JTextField</code>, meaning the next component added
 * will appear on the next line./*from w  w w . jav  a2 s  . co m*/
 * (Exception: Will not work if MigLayout's flowy layout constraint is applied,
 * but it is rarely used MigLayout feature and thus not a common concern; however
 * if you have set this layout constraint on your <code>JComponent</code> do not
 * attempt to use the wrap option of this method.)
 * @param label - the text to appear in front of the text field
 * @param rows - the length in rows of the text field 
 * @param cols - the length in columns of the text field
 * @param wrap - indicates is this component should be the last on the current line
 * @return the <code>JTextArea</code> added to the component
 */
public static JTextArea addLabeledTextArea(JComponent c, String label, int rows, int cols, boolean wrap) {
    JLabel l = new JLabel(label);
    c.add(l, "align left");

    JTextArea text = new JTextArea(rows, cols);
    if (wrap) {
        c.add(text, "align left, wrap");
    } else {
        c.add(text, "align left");
    }

    return text;
}

From source file:JTop.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*from w w  w  .j  a  v  a 2  s . c  o  m*/
private static void createAndShowGUI(JPanel jtop) {
    // Create and set up the window.
    JFrame frame = new JFrame("JTop");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    JComponent contentPane = (JComponent) frame.getContentPane();
    contentPane.add(jtop, BorderLayout.CENTER);
    contentPane.setOpaque(true); // content panes must be opaque
    contentPane.setBorder(new EmptyBorder(12, 12, 12, 12));
    frame.setContentPane(contentPane);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:cool.pandora.modeller.ui.jpanel.base.OrganizationProfileForm.java

@Override
protected JComponent createFormControl() {
    final JComponent form = new JPanel();
    form.setLayout(new BorderLayout());
    final JComponent formFields = createFormFields();
    form.add(formFields, BorderLayout.CENTER);

    return form;//from  w w  w .j a  v a 2s  . c om
}

From source file:net.sf.taverna.t2.activities.wsdl.views.WSDLActivityContextualView.java

/**
 * Gets the component from the {@link HTMLBasedActivityContextualView} and adds buttons to it
 * allowing XML splitters to be added//w  w w. j a v  a  2  s. co  m
 */
@Override
public JComponent getMainFrame() {
    final JComponent mainFrame = super.getMainFrame();
    JPanel flowPanel = new JPanel(new FlowLayout());

    addInputSplitter(mainFrame, flowPanel);
    addOutputSplitter(mainFrame, flowPanel);

    mainFrame.add(flowPanel, BorderLayout.SOUTH);
    return mainFrame;
}

From source file:com.siyeh.ig.logging.ClassWithoutLoggerInspection.java

@Override
public JComponent createOptionsPanel() {
    final JComponent panel = new JPanel(new BorderLayout());
    final ListTable table = new ListTable(
            new ListWrappingTableModel(loggerNames, InspectionGadgetsBundle.message("logger.class.name")));
    final JPanel tablePanel = UiUtils.createAddRemoveTreeClassChooserPanel(table,
            InspectionGadgetsBundle.message("choose.logger.class"));
    final CheckBox checkBox = new CheckBox(InspectionGadgetsBundle.message("super.class.logger.option"), this,
            "ignoreSuperLoggers");
    panel.add(tablePanel, BorderLayout.CENTER);
    panel.add(checkBox, BorderLayout.SOUTH);
    return panel;
}

From source file:com.brainflow.application.toplevel.Brainflow.java

private void initializeWorkspace() throws Exception {
    log.info("initializing workspace");
    brainFrame.getDockingManager().getWorkspace().setLayout(new BorderLayout());
    brainFrame.getDockingManager().getWorkspace().add(documentPane, "Center");

    JComponent canvas = DisplayManager.getInstance().getSelectedCanvas().getComponent();
    canvas.setRequestFocusEnabled(true);
    canvas.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));

    documentPane.setTabPlacement(DocumentPane.BOTTOM);
    documentPane.openDocument(new DocumentComponent(new JScrollPane(canvas), "Canvas-1"));
    documentPane.setActiveDocument("Canvas-1");

    log.info("initializing loading dock");
    initLoadingDock();/*www  . j  a v a  2 s . co m*/
    log.info("initializing project view");
    initProjectView();
    log.info("initializing image table view");
    initLoadableImageTableView();
    log.info("initializing control panel");
    initControlPanel();
    log.info("initializing event monitor");
    initEventBusMonitor();
    log.info("initializing log monitor");
    initLogMonitor();

    brainFrame.getDockingManager().beginLoadLayoutData();
    brainFrame.getDockingManager().setInitSplitPriority(DefaultDockingManager.SPLIT_EAST_WEST_SOUTH_NORTH);
    brainFrame.getDockingManager().loadLayoutData();

    brainFrame.toFront();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    brainFrame.setSize((int) screenSize.getWidth(), (int) screenSize.getHeight() - 50);
    brainFrame.setVisible(true);

    CanvasBar2 cbar = new CanvasBar2();

    /// TODO add automatic updating of canvas to Canvas Bar via EventBus
    //cbar.setImageCanvas(canvas);
    ////////////////////////////////////////////////////////////////////
    canvas.add(cbar.getComponent(), BorderLayout.NORTH);

}

From source file:brainflow.app.toplevel.BrainFlow.java

private void initializeWorkspace() throws Exception {
    StopWatch watch = new StopWatch();

    watch.start("laying out workspace");
    log.info("initializing workspace");

    //_frame.getDockableBarManager().getMainContainer().setLayout(new BorderLayout());
    //_frame.getDockableBarManager().getMainContainer().add(_tabbedPane, BorderLayout.CENTER);

    //brainFrame.getMainPanel().add(documentPane, BorderLayout.CENTER);
    brainFrame.getDockingManager().getWorkspace().setLayout(new BorderLayout());
    brainFrame.getDockingManager().getWorkspace().add(documentPane, BorderLayout.CENTER);

    brainFrame.getDockingManager().beginLoadLayoutData();
    brainFrame.getDockingManager().setInitSplitPriority(DefaultDockingManager.SPLIT_EAST_WEST_SOUTH_NORTH);

    JComponent canvas = DisplayManager.get().getSelectedCanvas().getComponent();
    canvas.setRequestFocusEnabled(true);
    canvas.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    watch.stopAndReport("laying out workspace");
    watch.start("opening document");
    documentPane.setTabPlacement(DocumentPane.BOTTOM);
    documentPane.openDocument(createCanvasDocument(DisplayManager.get().getSelectedCanvas(), "Canvas-1"));
    documentPane.setActiveDocument("Canvas-1");
    watch.stopAndReport("opening document");

    log.info("initializing loading dock");
    watch.start("init loading dock");
    initLoadingDock();/*w w  w . jav a2  s.c o m*/
    watch.stopAndReport("init loading dock");
    log.info("initializing project view");
    watch.start("init project view");
    initProjectView();
    watch.stopAndReport("init project view");
    log.info("initializing image table view");
    watch.start("init ploadable image table view");
    initLoadableImageTableView();
    watch.stopAndReport("init ploadable image table view");
    log.info("initializing control panel");
    watch.start("init control panel");
    initControlPanel();
    initCoordinatePanel();
    watch.stopAndReport("init control panel");
    log.info("initializing event monitor");
    watch.start("event bus monitor");
    initEventBusMonitor();
    log.info("initializing log monitor");
    watch.stopAndReport("event bus monitor");

    watch.start("log monitor");
    initLogMonitor();
    watch.stopAndReport("log monitor");

    watch.start("layout docks");

    brainFrame.getDockableBarManager().loadLayoutData();
    // brainFrame.toFront();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    brainFrame.setSize((int) screenSize.getWidth(), (int) screenSize.getHeight() - 50);

    watch.stopAndReport("layout docks");

    watch.start("canvas bar");
    CanvasBar cbar = new CanvasBar();
    canvas.add(cbar.getComponent(), BorderLayout.NORTH);
    watch.stopAndReport("canvas bar");

    brainFrame.getDockingManager().loadLayoutData();

}

From source file:org.jcurl.demo.smack.JCurlSmackClient.java

@Override
protected void startup() {
    getMainFrame().setJMenuBar(createMenuBar());
    miRoster.setSelected(true);//  ww w .  j av a2  s .c  om

    final JComponent pv = new JPanel();
    pv.setLayout(new BorderLayout());
    final Box conversation = Box.createVerticalBox();
    pv.add(new JScrollPane(conversation, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
    pv.add(new JScrollPane(sca, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS), BorderLayout.SOUTH);

    final JSplitPane ph = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    ph.setResizeWeight(0.8);
    ph.add(pv, JSplitPane.LEFT);
    ph.add(new JScrollPane(sro), JSplitPane.RIGHT);

    xmppRoster();
    show(ph);

    // connect the jabber account
    new Thread(new Runnable() {
        public void run() {
            try {
                // get uid + pwd from a .properties file
                final Properties p = loadClassProps(JCurlSmackClient.class, null);
                acc.setUid(XmppAddress.parse(p.getProperty("acc_uid")));
                acc.setPwd(p.getProperty("acc_pwd"));
                // login and get the present buddies
                acc.login(resource);
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        sro.setConn(acc.getConn());
                        // Wire up xmpp stuff:
                        final ChatManager cm = sro.getChatManager();
                        cm.addChatListener(sca);
                        cm.addChatListener(slo);
                    }
                });
            } catch (final IOException e) {
                throw new RuntimeException("Unhandled", e);
            } catch (final XMPPException e) {
                throw new RuntimeException("Unhandled", e);
            }
        }
    }).start();
}