Java Code Examples for java.awt.Frame#setLayout()

The following examples show how to use java.awt.Frame#setLayout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoScrollOnSelectAndAppend.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public AutoScrollOnSelectAndAppend() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException("Robot Creation Failed.");
    }
    frame = new Frame();
    frame.setSize(200, 200);
    frame.setLayout(new FlowLayout());

    textArea = new TextArea(5, 20);
    composeTextArea();
    frame.add(textArea);

    buttonHoldFocus = new Button("HoldFocus");
    frame.add(buttonHoldFocus);

    frame.setVisible(true);
    robot.waitForIdle();

    // Move mouse cursor on first row of text area.
    Point loc = textArea.getLocationOnScreen();
    robot.mouseMove(loc.x + 8, loc.y + 8);
    robot.waitForIdle();
}
 
Example 2
Source File: FocusTransitionTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void createAndShowGUI() {
    frame = new Frame("Test Frame");

    textField1 = new TextField(5);

    button = new Button("Go");
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            textField1.requestFocusInWindow();
            startUpdate();
        }
    });

    frame.setLayout(new FlowLayout());
    frame.setSize(400, 200);
    frame.add(textField1);
    frame.add(new TextField(5));
    frame.add(new TextField(5));
    frame.add(button);
    frame.setVisible(true);
}
 
Example 3
Source File: FocusTransitionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void createAndShowGUI() {
    frame = new Frame("Test Frame");

    textField1 = new TextField(5);

    button = new Button("Go");
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            textField1.requestFocusInWindow();
            startUpdate();
        }
    });

    frame.setLayout(new FlowLayout());
    frame.setSize(400, 200);
    frame.add(textField1);
    frame.add(new TextField(5));
    frame.add(new TextField(5));
    frame.add(button);
    frame.setVisible(true);
}
 
Example 4
Source File: OverScrollTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
OverScrollTest() {
    try {
        robot = new Robot();
    } catch (Exception ex) {
        throw new RuntimeException(ex.getMessage());
    }

    mainFrame = new Frame();
    mainFrame.setSize(400, 200);
    mainFrame.setLocation(200, 200);
    mainFrame.setLayout(new FlowLayout());

    textArea = new TextArea(2, 10);
    textArea.setSize(300, 100);
    textArea.setText("123456 789123");
    mainFrame.add(textArea);
    mainFrame.setVisible(true);
    textArea.requestFocusInWindow();
}
 
Example 5
Source File: CompositeFactory.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
private static RowHeaderTable createRowHeaderTable(final Composite composite, final int width, final int height, final int rowHeaderWidth, final int rowHeight, final boolean iconEnable, final boolean editable) {
    final Frame frame = SWT_AWT.new_Frame(composite);
    final FlowLayout frameLayout = new FlowLayout();
    frameLayout.setVgap(0);
    frame.setLayout(frameLayout);

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

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

    return table;
}
 
Example 6
Source File: RequestFocusAndHideTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
Example 7
Source File: RequestFocusAndHideTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
Example 8
Source File: CompositeFactory.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
private static RowHeaderTable createTable(Composite composite, int width,
		int height, int rowHeaderWidth, int rowHeight, boolean iconEnable,
		boolean editable) {
	Frame frame = SWT_AWT.new_Frame(composite);
	frame.setLayout(new FlowLayout());

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

	return table;
}
 
Example 9
Source File: SetEnabledPerformance.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {
    frame = new Frame();
    frame.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 0));
    frame.setSize(600, 600);
    frame.setLocationRelativeTo(null);
    for (int i = 1; i < 10001; ++i) {
        frame.add(new JButton("Button " + i));
    }
    frame.setVisible(true);
}
 
Example 10
Source File: ScrollSelectionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void initTestWindow() {
    mainFrame = new Frame("ScrollSelectionTest frame");
    mainFrame.setBounds(500, 0, 400, 200);

    textField = new TextField(40);
    textField.setText("abcdefghijklmnopqrstuvwxyz");
    mainFrame.add(textField);
    mainFrame.setLayout(new FlowLayout());
    textField.select(0, 20);
    mainFrame.setVisible(true);
}
 
Example 11
Source File: Find.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) {
   try {
     Proxy p = (Proxy)Class.forName(argv[1]).getConstructor(new Class[] {iiuf.db.Connection.class}).newInstance(new Object[] {new iiuf.db.fmpro.Connection(new URL(argv[0]))});
     
     String[] fields = new String[argv.length - 2];
     for(int i = 0; i < fields.length; i++)
fields[i] = argv[i + 2];
     
     find = new Find(p, Find.ENGLISH, "Field", new String[] {"AND", "OR"}, "Value", "Sorting", "Sort order:", fields);
     tv   = new TableView(p, Proxy.AND);
     find.addFindListener(tv);
     
     for(int i = 0; i < fields.length; i++)
tv.addColumn(fields[i]);
     
     Frame f = new Frame();
     Frame f2 = new Frame();
     f.add(find);
     f.pack();
     f.setVisible(true);

     VNav vnav = new VNav(500);
     vnav.setMinimum(-20);
     vnav.setMaximum(20);
     vnav.invertValue();
     f2.setLayout(new GridBagLayout());
     f2.add(tv, Awt.constraints(false,  GridBagConstraints.BOTH));
     f2.add(vnav, Awt.constraints(true, GridBagConstraints.VERTICAL));
     vnav.addAdjustmentListener(tv);
     f2.pack();
     f2.setVisible(true);
   } catch(Exception e) {
     e.printStackTrace();
   }
 }
 
Example 12
Source File: CycleThroughFrameTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void createAndShowInstructionFrame() {
    Button passButton = new Button("Pass");
    passButton.setEnabled(true);

    Button failButton = new Button("Fail");
    failButton.setEnabled(true);

    TextArea instructions = new TextArea(12, 70);
    instructions.setText(TEST_INSTRUCTIONS);

    instructionFrame = new Frame("Test Instructions");
    instructionFrame.add(passButton);
    instructionFrame.add(failButton);
    instructionFrame.add(instructions);
    instructionFrame.setSize(200,200);
    instructionFrame.setLayout(new FlowLayout());
    instructionFrame.pack();
    instructionFrame.setVisible(true);

    passButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
    });

    failButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
        throw new RuntimeException(FAIL_MESSAGE);
    });
}
 
Example 13
Source File: RequestFocusAndHideTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
Example 14
Source File: CycleThroughFrameTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void createAndShowInstructionFrame() {
    Button passButton = new Button("Pass");
    passButton.setEnabled(true);

    Button failButton = new Button("Fail");
    failButton.setEnabled(true);

    TextArea instructions = new TextArea(12, 70);
    instructions.setText(TEST_INSTRUCTIONS);

    instructionFrame = new Frame("Test Instructions");
    instructionFrame.add(passButton);
    instructionFrame.add(failButton);
    instructionFrame.add(instructions);
    instructionFrame.setSize(200,200);
    instructionFrame.setLayout(new FlowLayout());
    instructionFrame.pack();
    instructionFrame.setVisible(true);

    passButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
    });

    failButton.addActionListener(ae -> {
        dispose();
        testContinueFlag = false;
        throw new RuntimeException(FAIL_MESSAGE);
    });
}
 
Example 15
Source File: LightweightEventTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public EventBug() {
    super();
    testFrame = new Frame();
    testFrame.setLayout(new BorderLayout());
    this.setLayout(new BorderLayout());
    testFrame.add("Center", this);
    testFrame.pack();
    testFrame.setVisible(true);
}
 
Example 16
Source File: RequestFocusAndHideTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
Example 17
Source File: ModifierRobotKeyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void initializeGUI() {
    frame = new Frame("Test frame");
    canvas = new Canvas();
    canvas.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent event) { focusGained = true; }
    });
    canvas.addKeyListener(this);
    frame.setLayout(new BorderLayout());
    frame.add(canvas);
    frame.setSize(200, 200);
    frame.setVisible(true);
}
 
Example 18
Source File: CompositeFactory.java    From erflute with Apache License 2.0 5 votes vote down vote up
private static RowHeaderTable createTable(Composite composite, int width, int height, int rowHeaderWidth, int rowHeight,
        boolean iconEnable, boolean editable) {
    final Frame frame = SWT_AWT.new_Frame(composite);
    frame.setLayout(new FlowLayout());

    final Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    frame.add(panel);
    final RowHeaderTable table = new RowHeaderTable(width, height, rowHeaderWidth, rowHeight, iconEnable, editable);
    panel.add(table);

    return table;
}
 
Example 19
Source File: ComponentIsNotDrawnAfterRemoveAddTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public ComponentIsNotDrawnAfterRemoveAddTest() {
    frame = new Frame("ComponentIsNotDrawnAfterRemoveAddTest");
    frame.setSize(500, 500);
    frame.setLocation(200, 200);
    frame.setLayout(null);
    frame.setBackground(Color.RED);

    panel = new Panel();
    panel.setLayout(null);
    panel.setBounds(25, 100, 455, 295);
    panel.setBackground(Color.GREEN);

    for (int i = 0; i < 10; i++) {
        TestCanvas canv1 = new TestCanvas();
        canv1.setBounds(i * 45 + 5, 15, 30 + i, 30 + i);
        panel.add(canv1);
        compList.add(canv1);

        TestButton btn1 = new TestButton();
        btn1.setBounds(i * 45 + 5, 60, 30 + i, 30 + i);
        panel.add(btn1);
        compList.add(btn1);

        TestCanvas canv2 = new TestCanvas();
        canv2.setBounds(i * 45 + 5, 105, 30 + i, 30 + i);
        panel.add(canv2);
        compList.add(canv2);

        TestButton btn2 = new TestButton();
        btn2.setBounds(i * 45 + 5, 150, 30 + i, 30 + i);
        panel.add(btn2);
        compList.add(btn2);

        TestCanvas canv3 = new TestCanvas();
        canv3.setBounds(i * 45 + 5, 195, 30 + i, 30 + i);
        panel.add(canv3);
        compList.add(canv3);

        TestButton btn3 = new TestButton();
        btn3.setBounds(i * 45 + 5, 240, 30 + i, 30 + i);
        panel.add(btn3);
        compList.add(btn3);
    }

    frame.add(panel);
    frame.setVisible(true);
}
 
Example 20
Source File: PaintComponentFunction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Helper method for serialization.
 *
 * @param in
 *          the input stream from where to read the serialized object.
 * @throws IOException
 *           when reading the stream fails.
 * @throws ClassNotFoundException
 *           if a class definition for a serialized object could not be found.
 */
private void readObject( final ObjectInputStream in ) throws IOException, ClassNotFoundException {
  in.defaultReadObject();
  if ( PaintComponentFunction.isHeadless() == false ) {
    peerSupply = new Frame();
    peerSupply.setLayout( new BorderLayout() );
  }
}