當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。