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


Java Container.add方法代碼示例

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


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

示例1: createMenuButtons

import java.awt.Container; //導入方法依賴的package包/類
private void createMenuButtons(Container pane) {
  // Make a horizontal box at the bottom to hold menu buttons
  Box menuBox = Box.createHorizontalBox();
  pane.add(menuBox, BorderLayout.PAGE_END);
  menuBox.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY),
      BorderFactory.createEmptyBorder(2, 2, 2, 2)));

  // Add the menu buttons
  Font menuFont = new Font("Arial", Font.PLAIN, 12);

  // SEARCH button ------------
  searchBt = new JButton("Find subtitles", createImageIcon("iconSearch.png", "search icon"));
  searchBt.addActionListener(this);
  searchBt.setFont(menuFont);
  menuBox.add(searchBt);
  menuBox.add(Box.createRigidArea(new Dimension(2, 0)));

  // QUIT button ------------
  menuBox.add(Box.createHorizontalGlue());
  quitBt = new JButton("Quit", createImageIcon("iconTransparent.png", "use transparent icon for padding"));
  quitBt.addActionListener(this);
  quitBt.setFont(menuFont);
  menuBox.add(quitBt);
}
 
開發者ID:juliango202,項目名稱:jijimaku,代碼行數:25,代碼來源:AppGui.java

示例2: dockToolBar

import java.awt.Container; //導入方法依賴的package包/類
/**
 * Docks the associated toolbar at the secified edge and indicies.
 */
public void dockToolBar(final int edge, final int row, final int index) {
    final Container target = ourDockLayout.getTargetContainer();
    if (target == null)
        return;

    target.remove(ourToolBar);
    final JDialog floatFrame = getFloatingFrame();
    if (floatFrame != null) {
        floatFrame.setVisible(false);
        floatFrame.getContentPane().remove(ourToolBar);
    }

    ourConstraints.setEdge(edge);
    ourConstraints.setRow(row);
    ourConstraints.setIndex(index);

    target.add(ourToolBar, ourConstraints);
    ourToolBarShouldFloat = false;

    target.validate();
    target.repaint();
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:26,代碼來源:Handler.java

示例3: Swing05

import java.awt.Container; //導入方法依賴的package包/類
public Swing05() {
	setTitle("Keypad");
	setSize(300, 400);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	Container c = getContentPane();
	c.setLayout(new GridLayout(4, 3));

	for (int i = 1; i < 10; i++) {
		c.add(new JButton(String.valueOf(i)));
	}
	
	c.add(new JButton("*"));
	c.add(new JButton("0"));
	c.add(new JButton("#"));
	
	setResizable(false);
	setVisible(true);
}
 
開發者ID:BedrockDev,項目名稱:Sunrin2017,代碼行數:20,代碼來源:Swing05.java

示例4: addLabeledComponentToGBL

import java.awt.Container; //導入方法依賴的package包/類
private void addLabeledComponentToGBL( String name,
                                       JComponent c,
                                       GridBagLayout gbl,
                                       GridBagConstraints gbc,
                                       Container target ) {
    LabelV2 l = new LabelV2( name );
    GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
    gbcLabel.insets = new Insets( 2, 2, 2, 0 );
    gbcLabel.gridwidth = 1;
    gbcLabel.weightx = 0;

    if ( c == null )
      c = new JLabel( "" );

    gbl.setConstraints( l, gbcLabel );
    target.add( l );
    gbl.setConstraints( c, gbc );
    target.add( c );
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:Font2DTest.java

示例5: Swing04

import java.awt.Container; //導入方法依賴的package包/類
public Swing04() {
	setTitle("null");
	setSize(200, 200);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	Container c = getContentPane();
	c.setLayout(null);
	
	JButton btn1 = new JButton("One");
	btn1.setBounds(10, 10, 100, 50);
	
	JButton btn2 = new JButton("Two");
	btn2.setBounds(100, 100, 100, 50);
	
	c.add(btn1);
	c.add(btn2);
	
	setVisible(true);
}
 
開發者ID:BedrockDev,項目名稱:Sunrin2017,代碼行數:20,代碼來源:Swing04.java

示例6: addBooleanComboBox

import java.awt.Container; //導入方法依賴的package包/類
/**
 * Adds a ComboBox to select a boolean property
 * @param text text to be shown on a label
 * @param property property to be changed in Defaults
 * @param cont container where input field must be added
 */
protected void addBooleanComboBox(String text, final String property, Container cont) {
	JLabel label = new JLabel(text + ":");
	JComboBox combo = new JComboBox(new Object[] { Boolean.TRUE.toString(), Boolean.FALSE.toString() });
	combo.setName(property);
	label.setLabelFor(combo);
	combo.setSelectedItem(Defaults.get(property));
	// Sets maximum size to minimal one, otherwise springLayout will stretch this
	combo.setMaximumSize(new Dimension(combo.getMaximumSize().width, combo.getMinimumSize().height));
	combo.addItemListener(new ItemListener() {
		public void itemStateChanged(ItemEvent e) {
			Defaults.set(property, (String) e.getItem());
		}
	});
	cont.add(label);
	cont.add(combo);
}
 
開發者ID:HOMlab,項目名稱:QN-ACTR-Release,代碼行數:23,代碼來源:DefaultsEditor.java

示例7: addComponent

import java.awt.Container; //導入方法依賴的package包/類
private static void addComponent (Container container, Component component) {
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = c.gridy = GridBagConstraints.RELATIVE;
    c.gridheight = c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.weightx = c.weighty = 1.0;
    ((GridBagLayout)container.getLayout()).setConstraints (component,c);
    container.add (component);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:PlatformsCustomizer.java

示例8: updateGutterComponents

import java.awt.Container; //導入方法依賴的package包/類
private boolean updateGutterComponents(List<EditableLine> lines, Document doc,
                                       int startIndex, int endIndex)
{
    String text;
    try {
        text = doc.getText(startIndex, endIndex-startIndex);
    }
    catch (BadLocationException ex) { // should not happen
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
        return false;
    }

    boolean visibility = !text.trim().equals(""); // NOI18N
    int prevSelectedIndex = 0;
    boolean changed = false;
    Container gutter = getGutter(doc);
    for (EditableLine l : lines) {
        // make sure the selected index is correct (ascending in the group)
        if (l.getSelectedIndex() < prevSelectedIndex)
            l.setSelectedIndex(prevSelectedIndex);
        else
            prevSelectedIndex = l.getSelectedIndex();
        // add the component to the gutter if not there yet
        Component comp = l.getGutterComponent();
        if (comp.getParent() == null)
            gutter.add(comp, l.getPosition());
        // show/hide the component
        if (visibility != l.isVisible()) {
            comp.setVisible(visibility);
            changed = true;
        }
    }
    return changed;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:CustomCodeView.java

示例9: PreferencesFrame

import java.awt.Container; //導入方法依賴的package包/類
private PreferencesFrame() {
	setDefaultCloseOperation(HIDE_ON_CLOSE);
	setJMenuBar(new LogisimMenuBar(this, null));

	panels = new OptionsPanel[] { new TemplateOptions(this), new IntlOptions(this), new WindowOptions(this),
			new LayoutOptions(this), new ExperimentalOptions(this), new ForkOptions(this), };
	tabbedPane = new JTabbedPane();
	int intlIndex = -1;
	for (int index = 0; index < panels.length; index++) {
		OptionsPanel panel = panels[index];
		tabbedPane.addTab(panel.getTitle(), null, panel, panel.getToolTipText());
		if (panel instanceof IntlOptions)
			intlIndex = index;
	}

	JPanel buttonPanel = new JPanel();
	buttonPanel.add(close);
	close.addActionListener(myListener);

	Container contents = getContentPane();
	tabbedPane.setPreferredSize(new Dimension(450, 300));
	contents.add(tabbedPane, BorderLayout.CENTER);
	contents.add(buttonPanel, BorderLayout.SOUTH);

	if (intlIndex >= 0)
		tabbedPane.setSelectedIndex(intlIndex);

	LocaleManager.addLocaleListener(myListener);
	myListener.localeChanged();
	pack();
	setLocationRelativeTo(null);
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:33,代碼來源:PreferencesFrame.java

示例10: reset

import java.awt.Container; //導入方法依賴的package包/類
/** Resets panel back after monitoring search. Implements <code>ProgressMonitor</code> interface method. */
public void reset() {
    Container container = (Container) getComponent();
    
    if(!container.isAncestorOf(getUI())) {
        container.removeAll();
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.weightx = 1.0;
        constraints.weighty = 1.0;
        constraints.fill = GridBagConstraints.BOTH;
        container.add(getUI(), constraints);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:AdditionalWizardPanel.java

示例11: start

import java.awt.Container; //導入方法依賴的package包/類
public void start() {
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    comboBox = new JComboBox<String>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" });
    contentPane.setLayout(new FlowLayout());
    contentPane.add(comboBox);
    frame.setLocationRelativeTo(null);
    frame.pack();
    frame.setVisible(true);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:ComboPopupTest.java

示例12: addInputString

import java.awt.Container; //導入方法依賴的package包/類
/**
 * Adds an input field to insert a String
 * @param text text to be shown on a label
 * @param property property to be changed in Defaults
 * @param cont container where input field must be added
 */
protected void addInputString(String text, String property, Container cont) {
	JLabel label = new JLabel(text + ":");
	JTextField field = new JTextField(10);
	field.setName(property);
	label.setLabelFor(field);
	field.setText(Defaults.get(property));
	// Sets maximum size to minimal one, otherwise springLayout will stretch this
	field.setMaximumSize(new Dimension(field.getMaximumSize().width, field.getMinimumSize().height));
	field.addKeyListener(stringListener);
	field.addFocusListener(stringListener);
	registeredStringListener.add(field);
	cont.add(label);
	cont.add(field);
}
 
開發者ID:max6cn,項目名稱:jmt,代碼行數:21,代碼來源:DefaultsEditor.java

示例13: createDialog

import java.awt.Container; //導入方法依賴的package包/類
/**
 * Creates and returns a new <code>JDialog</code> wrapping
 * <code>this</code> centered on the <code>parent</code>
 * in the <code>parent</code>'s frame.
 * This method can be overriden to further manipulate the dialog,
 * to disable resizing, set the location, etc. Example:
 * <pre>
 *     class MyFileChooser extends JFileChooser {
 *         protected JDialog createDialog(Component parent) throws HeadlessException {
 *             JDialog dialog = super.createDialog(parent);
 *             dialog.setLocation(300, 200);
 *             dialog.setResizable(false);
 *             return dialog;
 *         }
 *     }
 * </pre>
 *
 * @param   parent  the parent component of the dialog;
 *                  can be <code>null</code>
 * @return a new <code>JDialog</code> containing this instance
 * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 * returns true.
 * @see java.awt.GraphicsEnvironment#isHeadless
 * @since 1.4
 */
protected JDialog createDialog(Component parent) throws HeadlessException {
    FileChooserUI ui = getUI();
    String title = ui.getDialogTitle(this);
    putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
                      title);

    JDialog dialog;
    Window window = JOptionPane.getWindowForComponent(parent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame)window, title, true);
    } else {
        dialog = new JDialog((Dialog)window, title, true);
    }
    dialog.setComponentOrientation(this.getComponentOrientation());

    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(this, BorderLayout.CENTER);

    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations =
        UIManager.getLookAndFeel().getSupportsWindowDecorations();
        if (supportsWindowDecorations) {
            dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
        }
    }
    dialog.pack();
    dialog.setLocationRelativeTo(parent);

    return dialog;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:57,代碼來源:JFileChooser.java

示例14: RRDraw

import java.awt.Container; //導入方法依賴的package包/類
public RRDraw() {
    super("File View Test Frame");
    setSize(350, 400);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    parent = this;
    rrDrawPanel = new RRDrawPanel();
    Container c = getContentPane();
    // The default BorderLayout will work better.
    // c.setLayout(new FlowLayout());

    JButton openButton = new JButton("Open");
    final JLabel statusbar = new JLabel("Output of your selection will go here");

    openButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser("images");

            int option = chooser.showOpenDialog(parent);
            if (option == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                BufferedImage loadImage = loadImage(file);
                statusbar.setText(file.getName() + " size " + loadImage.getWidth() + "x" + loadImage.getHeight());
                // setSize(loadImage.getWidth(), loadImage.getHeight());
                rrDrawPanel.setSize(loadImage.getHeight(), loadImage.getWidth());
            } else {
                statusbar.setText("You cancelled.");
            }
        }
    });

    JPanel north = new JPanel();
    north.add(openButton);
    north.add(statusbar);

    north.setBackground(Color.GRAY);
    north.setForeground(Color.BLUE);
    c.add(north, "First");
    c.add(new JScrollPane(rrDrawPanel), "Center");

}
 
開發者ID:marcelrv,項目名稱:XiaomiRobotVacuumProtocol,代碼行數:42,代碼來源:RRDraw.java

示例15: init

import java.awt.Container; //導入方法依賴的package包/類
public void init() {
    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    
    // Proxy info table
    grid = getPanel(new GridLayout(2,3,2,2));
    grid.add(getHeaderLabel("URL"));
    grid.add(getHeaderLabel("Proxy Host"));
    grid.add(getHeaderLabel("Proxy Port"));
    grid.add(urlTextField);
    hostLabel = getLabel("");
    portLabel = getLabel("");
    grid.add(hostLabel);
    grid.add(portLabel);        
    grid.validate();
    content.add(grid, BorderLayout.CENTER);
    
    // Button panel - SOUTH
    JPanel buttonPanel = getPanel(new FlowLayout());
    JButton button = new JButton("Detect Proxy");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    detectProxy();
                }
            });
        }
    });
    buttonPanel.add(button);
    content.add(buttonPanel, BorderLayout.SOUTH);
    
    // version panel - NORTH
    JPanel versionPanel = getPanel(new FlowLayout());
    String javaVersion = System.getProperty("java.runtime.version");
    JLabel versionLabel = getLabel("Java Version: "+javaVersion);
    versionPanel.add(versionLabel);
    content.add(versionPanel, BorderLayout.NORTH);
    validate();
    
    super.setSize(400,100);
}
 
開發者ID:jenkinsci,項目名稱:lib-commons-httpclient,代碼行數:43,代碼來源:PluginProxyTestApplet.java


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