Java Code Examples for javax.swing.JButton

The following examples show how to use javax.swing.JButton. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   Source File: AntActionInstance.java    License: Apache License 2.0 6 votes vote down vote up
public Component getToolbarPresenter () {
    class AntButton extends JButton implements PropertyChangeListener {
        public AntButton() {
            super(AntActionInstance.this);
            // XXX setVisible(false) said to be poor on GTK L&F; consider using #26338 instead
            setVisible(isEnabled());
            AntActionInstance.this.addPropertyChangeListener(WeakListeners.propertyChange(this, AntActionInstance.this));
        }
        public void propertyChange(PropertyChangeEvent evt) {
            if ("enabled".equals(evt.getPropertyName())) { // NOI18N
                setVisible(isEnabled());
            }
        }
    }
    return new AntButton();
}
 
Example 2
Source Project: snap-desktop   Source File: SnapApp.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handles an error.
 *
 * @param message An error message.
 * @param t       An exception or {@code null}.
 */
public void handleError(String message, Throwable t) {
    if (t != null) {
        t.printStackTrace();
    }
    Dialogs.showError("Error", message);
    getLogger().log(Level.SEVERE, message, t);

    ImageIcon icon = TangoIcons.status_dialog_error(TangoIcons.Res.R16);
    JLabel balloonDetails = new JLabel(message);
    JButton popupDetails = new JButton("Report");
    popupDetails.addActionListener(e -> {
        try {
            Desktop.getDesktop().browse(new URI("http://forum.step.esa.int/"));
        } catch (URISyntaxException | IOException e1) {
            getLogger().log(Level.SEVERE, message, e1);
        }
    });
    NotificationDisplayer.getDefault().notify("Error",
                                              icon,
                                              balloonDetails,
                                              popupDetails,
                                              NotificationDisplayer.Priority.HIGH,
                                              NotificationDisplayer.Category.ERROR);
}
 
Example 3
private JComponent createUpDown() {

        TableLayout layout = new TableLayout(new double[]{TableLayout.FILL},
                new double[]{TableLayout.FILL, 5, TableLayout.FILL});

        JPanel panel = new JPanel(layout);

        JButton upButton = new JButton(up);
        upButton.setFocusable(false);
        JButton downButton = new JButton(down);
        downButton.setFocusable(false);

        panel.add(upButton, "0,0");
        panel.add(downButton, "0,2");

        JPanel p = new JPanel(new FlowLayout());
        p.add(panel);
        return p;
    }
 
Example 4
Source Project: jar-explorer   Source File: JarExplorer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * builds a tool bar
 *
 * @return toolbar instance with components added and wired with event listeners
 */
private JToolBar buildToolBar() {

    JToolBar tb = new JToolBar();
    tb.addSeparator();
    tb.add(stopB = new JButton("Stop"));
    stopB.setCursor(Cursor.getDefaultCursor());
    stopB.setToolTipText("stops directory scan");
    tb.add(cleanB = new JButton("Clean"));
    cleanB.setToolTipText("cleans windows");
    tb.addSeparator();
    tb.add(new JLabel("Enter class to search:"));
    tb.addSeparator();
    tb.add(searchTF = new JTextField("enter class to search"));
    searchTF.setToolTipText("to start seach, provide a class name and hit 'Enter'");
    tb.addSeparator();
    tb.add(searchB = new JButton("Search"));
    searchB.setToolTipText("press to start search");
    tb.addSeparator();
    return tb;
}
 
Example 5
private JPanel createButtonPanel() {
    refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(this::refresh);

    passButton = new JButton("Pass");
    passButton.addActionListener(this::pass);
    passButton.setEnabled(false);

    failButton = new JButton("Fail");
    failButton.addActionListener(this::fail);
    failButton.setEnabled(false);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(Box.createHorizontalGlue());
    buttonPanel.add(refreshButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    buttonPanel.add(Box.createHorizontalGlue());
    return buttonPanel;
}
 
Example 6
Source Project: importer-exporter   Source File: BoundingBoxValidator.java    License: Apache License 2.0 6 votes vote down vote up
private void init() {
	setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
	setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/org/citydb/gui/images/map/map_icon.png")));
	setLayout(new GridBagLayout());
	setBackground(Color.WHITE);	

	messageLabel = new JLabel();
	messageLabel.setIcon(new ImageIcon(getClass().getResource("/org/citydb/gui/images/map/loader.gif")));
	messageLabel.setIconTextGap(10);

	button = new JButton(Language.I18N.getString("common.button.ok"));
	button.setVisible(false);

	add(messageLabel, GuiUtil.setConstraints(0, 0, 1, 0, GridBagConstraints.HORIZONTAL, 10, 10, 10, 10));
	add(button, GuiUtil.setConstraints(0, 1, 0, 0, GridBagConstraints.NONE, 10, 5, 10, 5));

	button.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			dispose();
		}
	});

	pack();
	setLocationRelativeTo(getOwner());
	setResizable(false);
}
 
Example 7
Source Project: freeinternals   Source File: JPanelForTree.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a panel tool bar to contain a {@code JTree} object.
 *
 * @param jTree The tree to be contained
 * @param frame The parent window
 */
public JPanelForTree(final JTree jTree, final JFrame frame) {
    if (jTree == null) {
        throw new IllegalArgumentException("[tree] cannot be null.");
    }

    this.tree = jTree;
    this.topLevelFrame = frame;
    this.tree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final javax.swing.event.TreeSelectionEvent evt) {
            treeSelectionChanged(evt);
        }
    });

    this.toolbar = new JToolBar();
    this.toolbarbtnDetails = new JButton("Details");
    this.initToolbar();

    this.layoutComponents();
}
 
Example 8
Source Project: TencentKona-8   Source File: Test7024235.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void run() {
    if (this.pane == null) {
        this.pane = new JTabbedPane();
        this.pane.addTab("1", new Container());
        this.pane.addTab("2", new JButton());
        this.pane.addTab("3", new JCheckBox());

        JFrame frame = new JFrame();
        frame.add(BorderLayout.WEST, this.pane);
        frame.pack();
        frame.setVisible(true);

        test("first");
    }
    else {
        test("second");
        if (this.passed || AUTO) { // do not close a frame for manual review
            SwingUtilities.getWindowAncestor(this.pane).dispose();
        }
        this.pane = null;
    }
}
 
Example 9
Source Project: jdk8u60   Source File: Test7024235.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void run() {
    if (this.pane == null) {
        this.pane = new JTabbedPane();
        this.pane.addTab("1", new Container());
        this.pane.addTab("2", new JButton());
        this.pane.addTab("3", new JCheckBox());

        JFrame frame = new JFrame();
        frame.add(BorderLayout.WEST, this.pane);
        frame.pack();
        frame.setVisible(true);

        test("first");
    }
    else {
        test("second");
        if (this.passed || AUTO) { // do not close a frame for manual review
            SwingUtilities.getWindowAncestor(this.pane).dispose();
        }
        this.pane = null;
    }
}
 
Example 10
Source Project: netbeans   Source File: ActionProviderSupport.java    License: Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({
    "CTL_BrokenPlatform_Close=Close",
    "AD_BrokenPlatform_Close=N/A",
    "# {0} - project name", "TEXT_BrokenPlatform=<html><p><strong>The project {0} has a broken platform reference.</strong></p><br><p> You have to fix the broken reference and invoke the action again.</p>",
    "MSG_BrokenPlatform_Title=Broken Platform Reference"
})
static void showPlatformWarning (@NonNull final Project project) {
    final JButton closeOption = new JButton(CTL_BrokenPlatform_Close());
    closeOption.getAccessibleContext().setAccessibleDescription(AD_BrokenPlatform_Close());
    final String projectDisplayName = ProjectUtils.getInformation(project).getDisplayName();
    final DialogDescriptor dd = new DialogDescriptor(
        TEXT_BrokenPlatform(projectDisplayName),
        MSG_BrokenPlatform_Title(),
        true,
        new Object[] {closeOption},
        closeOption,
        DialogDescriptor.DEFAULT_ALIGN,
        null,
        null);
    dd.setMessageType(DialogDescriptor.WARNING_MESSAGE);
    final Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);
    dlg.setVisible(true);
}
 
Example 11
Source Project: netbeans   Source File: JSFConfigurationPanelVisual.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (value instanceof JsfComponentImplementation) {
        JsfComponentImplementation item = (JsfComponentImplementation) value;
        Component comp = super.getTableCellRendererComponent(table, item.getDisplayName(), isSelected, false, row, column);
        if (comp instanceof JComponent) {
            ((JComponent)comp).setOpaque(isSelected);
        }
        return comp;
    } else if (value instanceof Boolean && booleanRenderer != null) {
            return booleanRenderer.getTableCellRendererComponent(table, value, isSelected, false, row, column);

    } else {
        if (value instanceof JButton && jbuttonRenderer != null) {
            return jbuttonRenderer.getTableCellRendererComponent(table, value, isSelected, false, row, column);
        }
        else {
            return super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
        }
    }
}
 
Example 12
protected JButton makeOkButton(String i18nKey) {
	Action okAction = new ResourceAction(i18nKey) {

		private static final long serialVersionUID = 1L;

		@Override
		public void loggedActionPerformed(ActionEvent e) {
			wasConfirmed = true;
			ok();
		}
	};
	JButton button = new JButton(okAction);
	getRootPane().setDefaultButton(button);

	return button;
}
 
Example 13
Source Project: netbeans   Source File: ImageViewer.java    License: Apache License 2.0 6 votes vote down vote up
/** Gets zoom button. */
private JButton getZoomButton(final int xf, final int yf) {
    // PENDING buttons should have their own icons.
    JButton button = new JButton(""+xf+":"+yf); // NOI18N
    if (xf < yf)
        button.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomOut") + " " + xf + " : " + yf);
    else
        button.setToolTipText (NbBundle.getBundle(ImageViewer.class).getString("LBL_ZoomIn") + " " + xf + " : " + yf);
    button.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(ImageViewer.class).getString("ACS_Zoom_BTN"));
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            customZoom(xf, yf);
        }
    });
    
    return button;
}
 
Example 14
public AttributeFileValueCellEditor(ParameterTypeAttributeFile type) {
	super(type);
	button = new JButton(new ResourceAction(true, "edit_attributefile") {

		private static final long serialVersionUID = 1L;

		@Override
		public void loggedActionPerformed(ActionEvent e) {
			buttonPressed();
		}
	});
	button.setMargin(new Insets(0, 0, 0, 0));
	button.setToolTipText("Edit or create attribute description files and data (XML).");
	addButton(button, GridBagConstraints.RELATIVE);

	addButton(createFileChooserButton(), GridBagConstraints.REMAINDER);
}
 
Example 15
Source Project: netbeans   Source File: FormEditorOperatorTest.java    License: Apache License 2.0 6 votes vote down vote up
/** Test design actions. */
public void testDesign() {
    FormDesignerOperator designer = new FormDesignerOperator(SAMPLE_FRAME);
    new PaletteViewAction().perform();
    ComponentPaletteOperator palette = new ComponentPaletteOperator();
    ComponentInspectorOperator.invokeNavigator();
    // attach Palette to better position because components are not visible
    // when screen resolution is too low
    palette.attachTo(OutputOperator.invoke(), AttachWindowAction.RIGHT);
    //add something there
    palette.expandSwingControls();
    palette.selectComponent("Label"); // NOI18N
    designer.clickOnComponent(designer.fakePane().getSource());
    palette.selectComponent("Button"); // NOI18N
    designer.clickOnComponent(designer.fakePane().getSource());
    palette.selectComponent("Text Field"); // NOI18N
    designer.clickOnComponent(designer.fakePane().getSource());
    // add second button next to the first one
    Component button1 = designer.findComponent(JButton.class);
    palette.selectComponent("Button"); // NOI18N
    designer.clickOnComponent(button1);
}
 
Example 16
/**
 * Standard constructor - creates a three button panel with the specified button labels.
 *
 * @param label1  the label for button 1.
 * @param label2  the label for button 2.
 * @param label3  the label for button 3.
 */
public L1R2ButtonPanel(final String label1, final String label2, final String label3) {

    setLayout(new BorderLayout());

    // create the pieces...
    this.left = new JButton(label1);

    final JPanel rightButtonPanel = new JPanel(new GridLayout(1, 2));
    this.right1 = new JButton(label2);
    this.right2 = new JButton(label3);
    rightButtonPanel.add(this.right1);
    rightButtonPanel.add(this.right2);

    // ...and put them together
    add(this.left, BorderLayout.WEST);
    add(rightButtonPanel, BorderLayout.EAST);

}
 
Example 17
Source Project: netbeans   Source File: CanYouQueryFromRenameTest.java    License: Apache License 2.0 6 votes vote down vote up
protected FileObject handleRename(String name) throws IOException {
    FileObject retValue;
    
    MyLoader l = (MyLoader)getLoader();
    try {
        RequestProcessor.getDefault().post(l).waitFinished(1000);
    } catch (InterruptedException ex) {
        throw (InterruptedIOException)new InterruptedIOException(ex.getMessage()).initCause(ex);
    }
    
    assertNotNull("In middle of creation", l.middle);

    l.v = l.lookup.lookup(JButton.class);
    
    retValue = super.handleRename(name);
    return retValue;
}
 
Example 18
Source Project: jdk8u_jdk   Source File: TestObject.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    JPanel panel = (JPanel) decoder.readObject();
    if (2 != panel.getComponents().length) {
        throw new Error("unexpected component count");
    }
    JButton button = (JButton) panel.getComponents()[0];
    if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected button text");
    }
    if (SwingConstants.CENTER != button.getVerticalAlignment()) {
        throw new Error("unexpected vertical alignment");
    }
    JLabel label = (JLabel) panel.getComponents()[1];
    if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected label text");
    }
    if (button != label.getLabelFor()) {
        throw new Error("unexpected component");
    }
}
 
Example 19
Source Project: marathonv5   Source File: ToolBarDemo2.java    License: Apache License 2.0 6 votes vote down vote up
protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) {
    // Look for the image.
    String imgLocation = "images/" + imageName + ".gif";
    URL imageURL = ToolBarDemo2.class.getResource(imgLocation);

    // Create and initialize the button.
    JButton button = new JButton();
    button.setActionCommand(actionCommand);
    button.setToolTipText(toolTipText);
    button.addActionListener(this);

    if (imageURL != null) { // image found
        button.setIcon(new ImageIcon(imageURL, altText));
    } else { // no image found
        button.setText(altText);
        System.err.println("Resource not found: " + imgLocation);
    }

    return button;
}
 
Example 20
Source Project: openjdk-jdk9   Source File: JemmyExt.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean isPressed(JButtonOperator button) {
    return button.getQueueTool().invokeSmoothly(new QueueTool.QueueAction<Boolean>("getModel().isPressed()") {

        @Override
        public Boolean launch() throws Exception {
            return ((JButton) button.getSource()).getModel().isPressed();
        }
    });
}
 
Example 21
Source Project: triplea   Source File: ClientSetupPanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
PlayerRow(
    final String playerName, final Collection<String> playerAlliances, final boolean enabled) {
  playerNameLabel.setText(playerName);
  enabledCheckBox.addActionListener(disablePlayerActionListener);
  enabledCheckBox.setSelected(enabled);
  final boolean hasAlliance = !playerAlliances.contains(playerName);
  alliance = new JButton(hasAlliance ? playerAlliances.toString() : "");
  alliance.setVisible(hasAlliance);
}
 
Example 22
Source Project: dragonwell8_jdk   Source File: Test4247606.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void init() {
    JButton button = new JButton("Button"); // NON-NLS: the button text
    button.setBorder(BorderFactory.createLineBorder(Color.red, 1));

    TitledBorder border = new TitledBorder("Bordered Pane"); // NON-NLS: the panel title
    border.setTitlePosition(TitledBorder.BELOW_BOTTOM);

    JPanel panel = create(button, border);
    panel.setBackground(Color.green);

    getContentPane().add(create(panel, BorderFactory.createEmptyBorder(10, 10, 10, 10)));
}
 
Example 23
Source Project: wpcleaner   Source File: OnePageWindow.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a Validate button.
 * 
 * @param listener Action listener.
 * @param icon Flag indicating if an icon should be used.
 * @return Validate button.
 */
public JButton createButtonValidate(ActionListener listener, boolean icon) {
  JButton button = Utilities.createJButton(
      icon ? "commons-approve-icon.png" : null,
      EnumImageSize.NORMAL,
      GT._T("Validate"), !icon,
      ConfigurationValueShortcut.VALIDATE);
  button.setActionCommand(ACTION_VALIDATE);
  button.addActionListener(listener);
  return button;
}
 
Example 24
Source Project: opensim-gui   Source File: DialogUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void addCloseButton(Dialog dDialog, ActionListener actionListener) {
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(Box.createRigidArea(new Dimension(50, 50)));
    buttonPanel.add(Box.createVerticalStrut(50));
    buttonPanel.add(Box.createGlue());
    dDialog.add(buttonPanel, BorderLayout.SOUTH);
    JButton closeButton = new JButton("Close");
    buttonPanel.add(closeButton);
    closeButton.addActionListener(actionListener);
    dDialog.doLayout();
    dDialog.pack();
}
 
Example 25
Source Project: pcgen   Source File: SkillInfoTab.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private void releaseMouse(JSpinner jSpinner)
{
	IntStream.range(0, jSpinner.getComponentCount())
	         .mapToObj(jSpinner::getComponent)
	         .filter(comp -> comp instanceof JButton)
	         .forEach(this::releaseMouse);
}
 
Example 26
Source Project: jdk8u_jdk   Source File: Test6943780.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    JTabbedPane pane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
    pane.addTab("first", new JButton("first"));
    pane.addTab("second", new JButton("second"));
    for (Component component : pane.getComponents()) {
        component.setSize(100, 100);
    }
}
 
Example 27
Source Project: netbeans   Source File: StopManager.java    License: Apache License 2.0 5 votes vote down vote up
private boolean displayServerRunning() {
    JButton cancelButton = new JButton();
    Mnemonics.setLocalizedText(cancelButton, NbBundle.getMessage(StopManager.class, "StopManager.CancelButton")); // NOI18N
    cancelButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(StopManager.class, "StopManager.CancelButtonA11yDesc")); //NOI18N

    JButton keepWaitingButton = new JButton();
    Mnemonics.setLocalizedText(keepWaitingButton, NbBundle.getMessage(StopManager.class, "StopManager.KeepWaitingButton")); // NOI18N
    keepWaitingButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(StopManager.class, "StopManager.KeepWaitingButtonA11yDesc")); //NOI18N

    JButton propsButton = new JButton();
    Mnemonics.setLocalizedText(propsButton, NbBundle.getMessage(StopManager.class, "StopManager.PropsButton")); // NOI18N
    propsButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(StopManager.class, "StopManager.PropsButtonA11yDesc")); //NOI18N

    String message = NbBundle.getMessage(StopManager.class, "MSG_ServerStillRunning");
    final NotifyDescriptor ndesc = new NotifyDescriptor(message,
            NbBundle.getMessage(StopManager.class, "StopManager.ServerStillRunningTitle"),
            NotifyDescriptor.YES_NO_CANCEL_OPTION,
            NotifyDescriptor.QUESTION_MESSAGE,
            new Object[] {keepWaitingButton, propsButton, cancelButton},
            NotifyDescriptor.CANCEL_OPTION); //NOI18N

    Object ret = Mutex.EVENT.readAccess(new Action<Object>() {
        @Override
        public Object run() {
            return DialogDisplayer.getDefault().notify(ndesc);
        }

    });

    if (cancelButton.equals(ret)) {
        stopRequested.set(false);
        return false;
    } else if (keepWaitingButton.equals(ret)) {
        return true;
    } else {
        displayAdminProperties(server);
        return false;
    }
}
 
Example 28
Source Project: MeteoInfo   Source File: MainToolBar.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void jButton_SelectActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.mapView.setMouseTool(MouseTools.SelectElements);
    if (this.mapLayout != null) {
        this.mapLayout.setMouseMode(MouseMode.Select);
    }

    setCurrentTool((JButton) evt.getSource());
}
 
Example 29
Source Project: netbeans   Source File: UpdateTo.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of UpdateTo */
public UpdateTo(RepositoryFile repositoryFile, boolean localChanges) {
    revisionPath = new RepositoryPaths(repositoryFile, null, null, getPanel().revisionTextField, getPanel().revisionSearchButton);
    revisionPath.setupBehavior(null, 0, null, SvnSearch.SEARCH_HELP_ID_UPDATE);
    revisionPath.addPropertyChangeListener(this);
    getPanel().warningLabel.setVisible(localChanges);
    okButton = new JButton(org.openide.util.NbBundle.getMessage(UpdateTo.class, "CTL_UpdateToForm_Action_Update")); // NOI18N
    okButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateTo.class, "ACSD_UpdateToForm_Action_Update")); // NOI18N
    cancelButton = new JButton(org.openide.util.NbBundle.getMessage(UpdateTo.class, "CTL_UpdateToForm_Action_Cancel")); // NOI18N
    cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UpdateTo.class, "ACSD_UpdateToForm_Action_Cancel")); // NOI18N
}
 
Example 30
public static void init() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame();
            frame.setLayout(new FlowLayout());
            JPanel p1 = new JPanel();
            button = new JButton("Test");
            p1.add(button);
            frame.add(p1);
            text = new WeakReference<JTextField>(new JTextField("Text"));
            p = new WeakReference<JPanel>(new JPanel(new FlowLayout()));
            p.get().add(text.get());
            frame.add(p.get());
            frame.setBounds(500, 400, 200, 200);
            frame.setVisible(true);
        }
    });

    Util.focusComponent(text.get(), 500);
    Util.clickOnComp(button, new Robot());
    //References to objects testes for memory leak are stored in Util.
    //Need to clean them
    Util.cleanUp();

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.remove(p.get());
        }
    });

    Util.waitForIdle(null);
    //After the next caret blink it automatically TextField references
    Thread.sleep(text.get().getCaret().getBlinkRate() * 2);
    Util.waitForIdle(null);
    assertGC();
}