下面列出了java.awt.Container#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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 );
}
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 );
}
/**
* Add a new button to a given component
*
* @param component Component to add the button to
* @param text Button's text or null
* @param icon Button's icon or null
* @param listener Button's ActionListener or null
* @param actionCommand Button's action command or null
* @param mnemonic Button's mnemonic (virtual key code) or 0
* @param toolTip Button's tooltip text or null
* @return Created button
*/
public static JButton addButton(Container component, String text, Icon icon,
ActionListener listener, String actionCommand, int mnemonic, String toolTip) {
JButton button = new JButton(text, icon);
if (listener != null)
button.addActionListener(listener);
if (actionCommand != null)
button.setActionCommand(actionCommand);
if (mnemonic > 0)
button.setMnemonic(mnemonic);
if (toolTip != null)
button.setToolTipText(toolTip);
if (component != null)
component.add(button);
return button;
}
private static void init(Container container) {
container.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 1;
JLabel label = new JLabel();
Dimension size = new Dimension(111, 0);
label.setPreferredSize(size);
label.setMinimumSize(size);
container.add(label, gbc);
gbc.gridx = 1;
gbc.weightx = 1;
container.add(new JScrollBar(JScrollBar.HORIZONTAL, 1, 111, 1, 1111), gbc);
gbc.gridx = 2;
gbc.gridy = 0;
gbc.weightx = 0;
gbc.weighty = 1;
container.add(new JScrollBar(JScrollBar.VERTICAL, 1, 111, 1, 1111), gbc);
}
/**
* Handles a click on the "previous" button, by displaying the previous panel in the sequence.
*/
public void previous() {
if (this.step > 0) {
final WizardPanel previousPanel = getWizardPanel(this.step - 1);
// tell the panel that we are returning
previousPanel.returnFromLaterStep();
final Container content = getContentPane();
content.remove(this.currentPanel);
content.add(previousPanel);
this.step = this.step - 1;
this.currentPanel = previousPanel;
setTitle("Step " + (this.step + 1));
enableButtons();
pack();
}
}
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 );
}
public Test6505027(JFrame main) {
Container container = main;
if (INTERNAL) {
JInternalFrame frame = new JInternalFrame();
frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
frame.setVisible(true);
JDesktopPane desktop = new JDesktopPane();
desktop.add(frame, new Integer(1));
container.add(desktop);
container = frame;
}
if (TERMINATE) {
this.table.putClientProperty(KEY, Boolean.TRUE);
}
TableColumn column = this.table.getColumn(COLUMNS[1]);
column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));
container.add(BorderLayout.NORTH, new JTextField());
container.add(BorderLayout.CENTER, new JScrollPane(this.table));
}
/**
* Adds fill components to empty cells in the first row and first column of the grid.
* This ensures that the grid spacing will be the same as shown in the designer.
* @param cols an array of column indices in the first row where fill components should be added.
* @param rows an array of row indices in the first column where fill components should be added.
*/
void addFillComponents( Container panel, int[] cols, int[] rows )
{
Dimension filler = new Dimension(10,10);
boolean filled_cell_11 = false;
CellConstraints cc = new CellConstraints();
if ( cols.length > 0 && rows.length > 0 )
{
if ( cols[0] == 1 && rows[0] == 1 )
{
/** add a rigid area */
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
filled_cell_11 = true;
}
}
for( int index = 0; index < cols.length; index++ )
{
if ( cols[index] == 1 && filled_cell_11 )
{
continue;
}
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
}
for( int index = 0; index < rows.length; index++ )
{
if ( rows[index] == 1 && filled_cell_11 )
{
continue;
}
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
}
}
/**
* TableFrame Constructor
*
* @param title
* @param _table Description of the Parameter
*/
public DataTableFrame(String title, DataTable _table) {
super(title);
table = _table;
JScrollPane scrollPane = new JScrollPane(table);
Container c = getContentPane();
c.add(scrollPane, BorderLayout.CENTER);
// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
pack();
// setVisible(true);
if(!OSPRuntime.appletMode) {
createMenuBar();
loadDisplayMenu();
}
}
private void createCostTypeCombo(Container parent) {
EquipmentModifierCostType[] types = EquipmentModifierCostType.values();
mCostType = new JComboBox<>(types);
mCostType.setSelectedItem(mRow.getCostAdjType());
mCostType.addActionListener(this);
mCostType.setMaximumRowCount(types.length);
UIUtilities.setToPreferredSizeOnly(mCostType);
parent.add(mCostType);
}
/**
* Adds fill components to empty cells in the first row and first column of the grid.
* This ensures that the grid spacing will be the same as shown in the designer.
* @param cols an array of column indices in the first row where fill components should be added.
* @param rows an array of row indices in the first column where fill components should be added.
*/
void addFillComponents( Container panel, int[] cols, int[] rows )
{
Dimension filler = new Dimension(10,10);
boolean filled_cell_11 = false;
CellConstraints cc = new CellConstraints();
if ( cols.length > 0 && rows.length > 0 )
{
if ( cols[0] == 1 && rows[0] == 1 )
{
/** add a rigid area */
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
filled_cell_11 = true;
}
}
for( int index = 0; index < cols.length; index++ )
{
if ( cols[index] == 1 && filled_cell_11 )
{
continue;
}
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
}
for( int index = 0; index < rows.length; index++ )
{
if ( rows[index] == 1 && filled_cell_11 )
{
continue;
}
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
}
}
/**
* Contructs the layout with a container for displaying chart and a control
* panel for selecting interactivity.
*
* @param args
*/
public static void main( String[] args )
{
final Regression_116630_swing siv = new Regression_116630_swing( );
JFrame jf = new JFrame( );
jf.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
jf.addComponentListener( siv );
Container co = jf.getContentPane( );
co.setLayout( new BorderLayout( ) );
co.add( siv, BorderLayout.CENTER );
Dimension dScreen = Toolkit.getDefaultToolkit( ).getScreenSize( );
Dimension dApp = new Dimension( 600, 400 );
jf.setSize( dApp );
jf.setLocation(
( dScreen.width - dApp.width ) / 2,
( dScreen.height - dApp.height ) / 2 );
jf.setTitle( siv.getClass( ).getName( ) + " [device=" //$NON-NLS-1$
+ siv.idr.getClass( ).getName( ) + "]" );//$NON-NLS-1$
ControlPanel cp = siv.new ControlPanel( siv );
co.add( cp, BorderLayout.SOUTH );
siv.idr.setProperty( IDeviceRenderer.UPDATE_NOTIFIER, siv );
jf.addWindowListener( new WindowAdapter( ) {
public void windowClosing( WindowEvent e )
{
siv.idr.dispose( );
}
} );
jf.setVisible( true );
}
private void layoutComponents() {
final Container content = this;
content.setLayout(new BorderLayout());
scrollPane = new JScrollPane(text);
content.add(scrollPane, BorderLayout.CENTER);
content.add(scrollPane, BorderLayout.CENTER);
final JPanel savePanel = new JPanel();
savePanel.setLayout(new BorderLayout());
savePanel.add(nextMessage, BorderLayout.CENTER);
savePanel.add(save, BorderLayout.WEST);
content.add(savePanel, BorderLayout.SOUTH);
}
private static void printTexture() {
f = new JFrame("Texture Printing Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
final TexturePaintPrintingTest gpt = new TexturePaintPrintingTest();
Container c = f.getContentPane();
c.add(BorderLayout.CENTER, gpt);
final JButton print = new JButton("Print");
print.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(gpt);
final boolean doPrint = job.printDialog();
if (doPrint) {
try {
job.print();
} catch (PrinterException ex) {
throw new RuntimeException(ex);
}
}
}
});
c.add(print, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
public MarioLike() {
// �^�C�g����ݒ�
setTitle("�}�b�v�X�N���[��");
// �T�C�Y�ύX�s��
setResizable(false);
// ���C���p�l�����쐬���ăt���[���ɒlj�
MainPanel panel = new MainPanel();
Container contentPane = getContentPane();
contentPane.add(panel);
// �p�l���T�C�Y�ɍ��킹�ăt���[���T�C�Y�������ݒ�
pack();
}
private StatisticsDialog(JFrame parent, String circuitName, StatisticsTableModel model) {
super(parent, true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle(Strings.get("statsDialogTitle", circuitName));
JTable table = new StatisticsTable();
TableSorter mySorter = new TableSorter(model, table.getTableHeader());
Comparator<String> comp = new CompareString("", Strings.get("statsTotalWithout"),
Strings.get("statsTotalWith"));
mySorter.setColumnComparator(String.class, comp);
table.setModel(mySorter);
JScrollPane tablePane = new JScrollPane(table);
JButton button = new JButton(Strings.get("statsCloseButton"));
button.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.add(button);
Container contents = this.getContentPane();
contents.setLayout(new BorderLayout());
contents.add(tablePane, BorderLayout.CENTER);
contents.add(buttonPanel, BorderLayout.PAGE_END);
this.pack();
this.setLocationRelativeTo(null);
Dimension pref = contents.getPreferredSize();
if (pref.width > 750 || pref.height > 550) {
if (pref.width > 750)
pref.width = 750;
if (pref.height > 550)
pref.height = 550;
this.setSize(pref);
}
}
private static void createInputField(JDialog dialog, Container container, final IExpr action, int headID,
IExpr[] result, EvalEngine engine) {
String defaultInput = action.toString();
ISymbol dynamic = null;
if (action == F.Null) {
defaultInput = "";
} else if (action.isAST(F.Dynamic, 2) && action.first().isSymbol() && !action.first().isBuiltInSymbol()) {
dynamic = (ISymbol) action.first();
defaultInput = dynamic.toString();
}
JTextField inputField = new JTextField(defaultInput, 10);
container.add(inputField);
MyDocumentListener dl = new MyDocumentListener(inputField, dynamic, headID);
inputField.getDocument().addDocumentListener(dl);
// inputField.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// try {
// System.out.println(inputField.getText());
// } catch (DialogReturnException rex) {
// result[0] = rex.getValue();
// dialog.dispose();
// } catch (RuntimeException rex) {
// //
// }
// }
// });
}
/**
* Initialize print dialog.
*/
void initPrintDialog(int x, int y,
PrintService[] services,
int defaultServiceIndex,
DocFlavor flavor,
PrintRequestAttributeSet attributes)
{
this.services = services;
this.defaultServiceIndex = defaultServiceIndex;
this.asOriginal = attributes;
this.asCurrent = new HashPrintRequestAttributeSet(attributes);
this.psCurrent = services[defaultServiceIndex];
this.docFlavor = flavor;
SunPageSelection pages =
(SunPageSelection)attributes.get(SunPageSelection.class);
if (pages != null) {
isAWT = true;
}
Container c = getContentPane();
c.setLayout(new BorderLayout());
tpTabs = new JTabbedPane();
tpTabs.setBorder(new EmptyBorder(5, 5, 5, 5));
String gkey = getMsg("tab.general");
int gmnemonic = getVKMnemonic("tab.general");
pnlGeneral = new GeneralPanel();
tpTabs.add(gkey, pnlGeneral);
tpTabs.setMnemonicAt(0, gmnemonic);
String pkey = getMsg("tab.pagesetup");
int pmnemonic = getVKMnemonic("tab.pagesetup");
pnlPageSetup = new PageSetupPanel();
tpTabs.add(pkey, pnlPageSetup);
tpTabs.setMnemonicAt(1, pmnemonic);
String akey = getMsg("tab.appearance");
int amnemonic = getVKMnemonic("tab.appearance");
pnlAppearance = new AppearancePanel();
tpTabs.add(akey, pnlAppearance);
tpTabs.setMnemonicAt(2, amnemonic);
c.add(tpTabs, BorderLayout.CENTER);
updatePanels();
JPanel pnlSouth = new JPanel(new FlowLayout(FlowLayout.TRAILING));
btnApprove = createExitButton("button.print", this);
pnlSouth.add(btnApprove);
getRootPane().setDefaultButton(btnApprove);
btnCancel = createExitButton("button.cancel", this);
handleEscKey(btnCancel);
pnlSouth.add(btnCancel);
c.add(pnlSouth, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
dispose(CANCEL);
}
});
getAccessibleContext().setAccessibleDescription(getMsg("dialog.printtitle"));
setResizable(false);
setLocation(x, y);
pack();
}
/**
* Initialize print dialog.
*/
void initPrintDialog(int x, int y,
PrintService[] services,
int defaultServiceIndex,
DocFlavor flavor,
PrintRequestAttributeSet attributes)
{
this.services = services;
this.defaultServiceIndex = defaultServiceIndex;
this.asOriginal = attributes;
this.asCurrent = new HashPrintRequestAttributeSet(attributes);
this.psCurrent = services[defaultServiceIndex];
this.docFlavor = flavor;
SunPageSelection pages =
(SunPageSelection)attributes.get(SunPageSelection.class);
if (pages != null) {
isAWT = true;
}
if (attributes.get(DialogOnTop.class) != null) {
setAlwaysOnTop(true);
}
Container c = getContentPane();
c.setLayout(new BorderLayout());
tpTabs = new JTabbedPane();
tpTabs.setBorder(new EmptyBorder(5, 5, 5, 5));
String gkey = getMsg("tab.general");
int gmnemonic = getVKMnemonic("tab.general");
pnlGeneral = new GeneralPanel();
tpTabs.add(gkey, pnlGeneral);
tpTabs.setMnemonicAt(0, gmnemonic);
String pkey = getMsg("tab.pagesetup");
int pmnemonic = getVKMnemonic("tab.pagesetup");
pnlPageSetup = new PageSetupPanel();
tpTabs.add(pkey, pnlPageSetup);
tpTabs.setMnemonicAt(1, pmnemonic);
String akey = getMsg("tab.appearance");
int amnemonic = getVKMnemonic("tab.appearance");
pnlAppearance = new AppearancePanel();
tpTabs.add(akey, pnlAppearance);
tpTabs.setMnemonicAt(2, amnemonic);
c.add(tpTabs, BorderLayout.CENTER);
updatePanels();
JPanel pnlSouth = new JPanel(new FlowLayout(FlowLayout.TRAILING));
btnApprove = createExitButton("button.print", this);
pnlSouth.add(btnApprove);
getRootPane().setDefaultButton(btnApprove);
btnCancel = createExitButton("button.cancel", this);
handleEscKey(btnCancel);
pnlSouth.add(btnCancel);
c.add(pnlSouth, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
dispose(CANCEL);
}
});
getAccessibleContext().setAccessibleDescription(getMsg("dialog.printtitle"));
setResizable(false);
setLocation(x, y);
pack();
}
public ScreenshotsFrame() {
super("Lights");
// The the HueSDK singleton.
phHueSDK = PHHueSDK.getInstance();
Container content = getContentPane();
// Get the selected bridge.
PHBridge bridge = phHueSDK.getSelectedBridge();
// To get lights use the Resource Cache.
allLights = bridge.getResourceCache().getAllLights();
JScrollPane listPane = new JScrollPane(lightIdentifiersList);
listPane.setPreferredSize(new Dimension(300,100));
JPanel listPanel = new JPanel();
listPanel.setBackground(Color.white);
listPanel.add(listPane);
content.add(listPanel);
// First Area
JLabel labelArea1 = new JLabel("Left area light");
labelArea1.setHorizontalAlignment(SwingConstants.CENTER);
labelArea1.setBounds(20, 40, 230, 16);
content.add(labelArea1);
comboBox_area_1.setBounds(20, 60, 230, 27);
comboBox_area_1.addItem("");
content.add(comboBox_area_1);
color1.setBounds(20, 85, 230, 32);
content.add(color1);
// Second Area
JLabel labelArea2 = new JLabel("Center area light");
labelArea2.setHorizontalAlignment(SwingConstants.CENTER);
labelArea2.setBounds(255, 40, 230, 16);
content.add(labelArea2);
comboBox_area_2.setBounds(255, 60, 230, 27);
comboBox_area_2.addItem("");
content.add(comboBox_area_2);
color2.setBounds(255, 85, 230, 32);
content.add(color2);
// Third Area
JLabel labelArea3 = new JLabel("Right area light");
labelArea3.setHorizontalAlignment(SwingConstants.CENTER);
labelArea3.setBounds(490, 40, 230, 16);
content.add(labelArea3);
comboBox_area_3.setBounds(490, 60, 230, 27);
comboBox_area_3.addItem("");
content.add(comboBox_area_3);
color3.setBounds(490, 85, 230, 32);
content.add(color3);
log.setBounds(490, 60, 230, 32);
content.add(log);
// Fill lists with lights
for (PHLight light : allLights) {
comboBox_area_1.addItem(light.getIdentifier() + " " + light.getName() );
comboBox_area_2.addItem(light.getIdentifier() + " " + light.getName() );
comboBox_area_3.addItem(light.getIdentifier() + " " + light.getName() );
}
// Start / Stop button
changeColourButton.addActionListener(new ScreenshotProcessor());
Border buttonPanelBorder = BorderFactory.createEmptyBorder();
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.white);
buttonPanel.setBorder(buttonPanelBorder);
buttonPanel.add(changeColourButton);
content.add(buttonPanel, BorderLayout.SOUTH);
setPreferredSize(new Dimension(740,400));
pack();
setVisible(true);
}