当前位置: 首页>>代码示例>>Java>>正文


Java Panel.add方法代码示例

本文整理汇总了Java中java.awt.Panel.add方法的典型用法代码示例。如果您正苦于以下问题:Java Panel.add方法的具体用法?Java Panel.add怎么用?Java Panel.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Panel的用法示例。


在下文中一共展示了Panel.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createObjects

import java.awt.Panel; //导入方法依赖的package包/类
void createObjects() {
    textArea = new TextArea( bigString() );
    robot = Util.createRobot();

    Panel panel = new Panel();
    panel.setLayout( new GridLayout(3,3) );

    for( int y=0; y<3; ++y ) {
        for( int x=0; x<3; ++x ) {
            if( x==1 && y==1 ) {
                panel.add( textArea );
            } else {
                panel.add( new Panel() );
            }
        }
    }

    Frame frame = new Frame( "TextArea cursor icon test" );
    frame.setSize( 300, 300 );
    frame.add( panel );
    frame.setVisible( true );
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:23,代码来源:SelectionAutoscrollTest.java

示例2: init

import java.awt.Panel; //导入方法依赖的package包/类
private void init(Component parent, String  title, String message,
                  String buttonText) {
    Panel p = new Panel();
    add("Center", new Label(message));
    Button btn = new Button(buttonText);
    btn.addActionListener(this);
    p.add(btn);
    add("South", p);
    pack();

    Dimension dDim = getSize();
    if (parent != null) {
        Rectangle fRect = parent.getBounds();
        setLocation(fRect.x + ((fRect.width - dDim.width) / 2),
                    fRect.y + ((fRect.height - dDim.height) / 2));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:WPrinterJob.java

示例3: init

import java.awt.Panel; //导入方法依赖的package包/类
@Override
public void init() {
    tf = new TextField(20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                     + "The text 012345 should be selected in the TextField.\n"
                                     + "If this is what you observe, then the test passes.\n"
                                     + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:21,代码来源:SelectionVisible.java

示例4: WeaponEditor

import java.awt.Panel; //导入方法依赖的package包/类
/**
 * Creates a new {@link WeaponEditor}.
 *
 * @param owner The owning row.
 * @param weapons The weapons to modify.
 * @param weaponClass The {@link Class} of weapons.
 */
public WeaponEditor(ListRow owner, List<WeaponStats> weapons, Class<? extends WeaponStats> weaponClass) {
    super(new BorderLayout());
    mOwner = owner;
    mWeaponClass = weaponClass;
    mAddButton = new IconButton(StdImage.ADD, ADD_TOOLTIP, () -> addWeapon());
    mDeleteButton = new IconButton(StdImage.REMOVE, REMOVE_TOOLTIP, () -> mOutline.deleteSelection());
    mDeleteButton.setEnabled(false);
    Panel top = new Panel(new BorderLayout());
    Panel left = new Panel(new PrecisionLayout());
    left.add(mAddButton);
    left.add(mDeleteButton);
    top.add(left, BorderLayout.WEST);
    top.add(createOutline(weapons, weaponClass), BorderLayout.CENTER);
    add(top, BorderLayout.NORTH);
    add(createEditorPanel(), BorderLayout.CENTER);
    setName(toString());
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:25,代码来源:WeaponEditor.java

示例5: init

import java.awt.Panel; //导入方法依赖的package包/类
public void init ()
{
  initted = true;

  Panel p = new Panel ();
  p.setLayout (new GridLayout (3, 1));

  List l = new List (5, true);
  for (int i = 0; i < 10; i++)
    l.add ("List item " + i);

  p.add (l);

  add (p, "Center");

  Button cb = new Button ("Close");
  cb.addActionListener(new ActionListener () {
      public void actionPerformed (ActionEvent e) {
        dispose();
      }
    });

  add (cb, "South");
  setTitle ("List");
  pack();
}
 
开发者ID:vilie,项目名称:javify,代码行数:27,代码来源:Demo.java

示例6: Simbatch

import java.awt.Panel; //导入方法依赖的package包/类
/** Construct a batch version of Simbad simulator */
public Simbatch(EnvironmentDescription ed, boolean do3DRendering) {
	counter = 0;
	world = new World(ed);
	// !!!!
	// We need absolutly to show the 3d world in a window
	// otherwise it reveal a memory bug in java3d
	// see Bug ID: 4727054
	// !!!!!
	canvas3d = world.getCanvas3D();
	frame = new Frame();
	panel = new Panel();
	panel.setLayout(new BorderLayout());
	panel.add(canvas3d);

	frame.add(panel);
	frame.pack();
	frame.setSize(100, 100);
	frame.setVisible(true);
	if (!do3DRendering) {
		frame.hide();
		// Do not render
		canvas3d.stopRenderer();
	}
	simulator = new Simulator(null, world, ed);
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:27,代码来源:Simbatch.java

示例7: addDirectoryField

import java.awt.Panel; //导入方法依赖的package包/类
/**
 * Adds the directory field.
 *
 * @param label
 *            the label
 * @param defaultPath
 *            the default path
 * @param columns
 *            the columns
 */
public void addDirectoryField(String label, String defaultPath, int columns) {
	addStringField(label, defaultPath, columns);
	if (isHeadless())
		return;

	TextField text = (TextField) stringField.lastElement();
	GridBagLayout layout = (GridBagLayout) getLayout();
	GridBagConstraints constraints = layout.getConstraints(text);

	Button button = new Button("Browse...");
	DirectoryListener listener = new DirectoryListener("Browse for " + label, text);
	button.addActionListener(listener);
	button.addKeyListener(this);

	Panel panel = new Panel();
	panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
	panel.add(text);
	panel.add(button);

	layout.setConstraints(panel, constraints);
	add(panel);
}
 
开发者ID:thorstenwagner,项目名称:ij-ridgedetection,代码行数:33,代码来源:GenericDialogPlus.java

示例8: addFileField

import java.awt.Panel; //导入方法依赖的package包/类
/**
 * Adds the file field.
 *
 * @param label
 *            the label
 * @param defaultPath
 *            the default path
 * @param columns
 *            the columns
 */
public void addFileField(String label, String defaultPath, int columns) {
	addStringField(label, defaultPath, columns);
	if (isHeadless())
		return;

	TextField text = (TextField) stringField.lastElement();
	GridBagLayout layout = (GridBagLayout) getLayout();
	GridBagConstraints constraints = layout.getConstraints(text);

	Button button = new Button("Browse...");
	FileListener listener = new FileListener("Browse for " + label, text);
	button.addActionListener(listener);
	button.addKeyListener(this);

	Panel panel = new Panel();
	panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
	panel.add(text);
	panel.add(button);

	layout.setConstraints(panel, constraints);
	add(panel);
}
 
开发者ID:thorstenwagner,项目名称:ij-ridgedetection,代码行数:33,代码来源:GenericDialogPlus.java

示例9: displayColors

import java.awt.Panel; //导入方法依赖的package包/类
private void displayColors(World world) {
	this.setSize(600, 800);
	
	for (byte i = 1; i <= num; i++) {
		Panel pnl = new Panel();
		pnl.setPreferredSize(new Dimension(pnlSize + 8, pnlSize + 32));
		Panel col = new Panel();
		col.setPreferredSize(new Dimension(pnlSize, pnlSize));
		col.setBackground(world.getType(i).getColor());
		pnl.add(col);
		Label lb = new Label();
		lb.setText(world.getType(i).getName() + " " + Integer.toString(i));
		pnl.add(lb);
		add(pnl);
	}
}
 
开发者ID:matortheeternal,项目名称:JVoxelEngine,代码行数:17,代码来源:WorldTester.java

示例10: SwingWorkerCompletionWaiter

import java.awt.Panel; //导入方法依赖的package包/类
/**
 * Constructor
 * 
 * @param pJDialog Waiting window showed during download
 */
public SwingWorkerCompletionWaiter(JDialog pJDialog) {
  this.dialog = pJDialog;

  setjLabelMainText(new JLabel("Etape 1/3 : D�marrage..."));

  Panel panel = new Panel();
  panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
  panel.add(new JLabel(TournamentUtil.WAITING_WINDOW_TITLE));
  panel.add(getjLabelMainText());

  dialog.setResizable(false);
  dialog.setTitle(TournamentUtil.WAITING_WINDOW_TITLE);
  dialog.setSize(new Dimension(400, 200));
  dialog.setLocationRelativeTo(null);
  dialog.setContentPane(panel);
}
 
开发者ID:SGirousse,项目名称:GOTE,代码行数:22,代码来源:UpdateResultsButton.java

示例11: Simbatch

import java.awt.Panel; //导入方法依赖的package包/类
public Simbatch(EnvironmentDescription ed, boolean do3DRendering) {
  counter = 0;
  world = new World(ed);
  // !!!!
  // We need absolutly to show the 3d world in a window
  // otherwise it reveal a memory bug in java3d
  // see Bug ID: 4727054
  // !!!!!
  canvas3d = world.getCanvas3D();
  frame = new Frame();
  panel = new Panel();
  panel.setLayout(new BorderLayout());
  panel.add(canvas3d);

  frame.add(panel);
  frame.pack();
  frame.setSize(100, 100);
  frame.setVisible(true);
  if (!do3DRendering) {
    frame.hide();
    // Do not render
    canvas3d.stopRenderer();
  }
  simulator = new Simulator(null, world, ed);
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:26,代码来源:Simbatch.java

示例12: createRowHeaderTable

import java.awt.Panel; //导入方法依赖的package包/类
private static RowHeaderTable createRowHeaderTable(Composite composite,
		int width, int height, int rowHeaderWidth, int rowHeight,
		boolean iconEnable, boolean editable) {
	Frame frame = SWT_AWT.new_Frame(composite);
	FlowLayout frameLayout = new FlowLayout();
	frameLayout.setVgap(0);
	frame.setLayout(frameLayout);

	Panel panel = new Panel();
	FlowLayout panelLayout = new FlowLayout();
	panelLayout.setVgap(0);
	panel.setLayout(panelLayout);
	frame.add(panel);

	RowHeaderTable table = new RowHeaderTable(width, height,
			rowHeaderWidth, rowHeight, iconEnable, editable);
	panel.add(table);

	return table;
}
 
开发者ID:justinkwony,项目名称:ermaster-nhit,代码行数:21,代码来源:CompositeFactory.java

示例13: init

import java.awt.Panel; //导入方法依赖的package包/类
@Override
public void init() {
    tf = new TextArea(3, 20);
    tf.setText("0123456789");
    tf.select(0, 6);

    final TextArea ta = new TextArea("INSTRUCTIONS:\n"
                                             + "The text 012345 should be selected in the TextArea.\n"
                                             + "If this is what you observe, then the test passes.\n"
                                             + "Otherwise, the test fails.", 40, 5,
                                     TextArea.SCROLLBARS_NONE);
    ta.setEditable(false);
    ta.setPreferredSize(new Dimension(300, 70));
    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    panel.add(tf);
    setLayout(new BorderLayout());
    add(ta, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:21,代码来源:SelectionVisible.java

示例14: init

import java.awt.Panel; //导入方法依赖的package包/类
/**
 * Test fails if it throws any exception.
 *
 * @throws Exception
 */
private void init() throws Exception {

    if (!System.getProperty("os.name").startsWith("Windows")) {
        System.out.println("This is Windows only test.");
        return;
    }

    final Frame frame = new Frame("AWT Frame");
    frame.pack();
    frame.setSize(200, 200);
    FramePeer frame_peer = AWTAccessor.getComponentAccessor()
                                .getPeer(frame);
    Class comp_peer_class
            = Class.forName("sun.awt.windows.WComponentPeer");
    Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
    hwnd_field.setAccessible(true);
    long hwnd = hwnd_field.getLong(frame_peer);

    Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
    Constructor constructor
            = clazz.getConstructor(new Class[]{long.class});
    final Frame embedded_frame
            = (Frame) constructor.newInstance(new Object[]{
                new Long(hwnd)});;
    final JComboBox<String> combo = new JComboBox<>(new String[]{
        "Item 1", "Item 2"
    });
    combo.setSelectedIndex(1);
    final Panel p = new Panel();
    p.setLayout(new BorderLayout());
    embedded_frame.add(p, BorderLayout.CENTER);
    embedded_frame.validate();
    p.add(combo);
    p.validate();
    frame.setVisible(true);
    Robot robot = new Robot();
    robot.delay(2000);
    Rectangle clos = new Rectangle(
            combo.getLocationOnScreen(), combo.getSize());
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (!combo.isPopupVisible()) {
        throw new RuntimeException("Combobox popup is not visible!");
    }
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height + 3);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (combo.getSelectedIndex() != 0) {
        throw new RuntimeException("Combobox selection has not changed!");
    }
    embedded_frame.remove(p);
    embedded_frame.dispose();
    frame.dispose();

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:EmbeddedFrameGrabTest.java

示例15: start

import java.awt.Panel; //导入方法依赖的package包/类
public void start() {
    String[] instructions = new String[] {
        "1. Notice components in test window: main-panel, box-for-text,"
            +" 2 scroll-sliders, and 4 scroll-buttons.",
        "2. Hover mouse over box-for-text."
            +" Make sure, that mouse cursor is TextCursor (a.k.a. \"beam\").",
        "3. Hover mouse over each of components (see item 1), except for box-for-text."
            +" Make sure, that cursor is DefaultCursor (arrow).",
        "4. Drag mouse (using any mouse button) from box-for-text to every"
            +" component in item 1, and also outside application window."
            +" Make sure, that cursor remains TextCursor while mouse button is pressed.",
        "5. Repeat item 4 for each other component in item 1, except for box-for-text,"
            +" _but_ now make sure that cursor is DefaultCursor.",
        "6. If cursor behaves as described in items 2-3-4-5, then test passed; otherwise it failed."
    };
    Sysout.createDialogWithInstructions( instructions );

    Panel panel = new Panel();
    panel.setLayout( new GridLayout(3,3) );

    for( int y=0; y<3; ++y ) {
        for( int x=0; x<3; ++x ) {
            if( x==1 && y==1 ) {
                panel.add( new TextArea( bigString() ) );
            } else {
                panel.add( new Panel() );
            }
        }
    }

    Frame frame = new Frame( "TextArea cursor icon test" );
    frame.setSize( 300, 300 );
    frame.add( panel );
    frame.setVisible( true );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:36,代码来源:HoveringAndDraggingTest.java


注:本文中的java.awt.Panel.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。