当前位置: 首页>>代码示例>>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;未经允许,请勿转载。