本文整理汇总了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);
}
示例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();
}
示例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);
}
示例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 );
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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");
}
示例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);
}