javax.swing.JButton Java Examples

The following examples show how to use javax.swing.JButton. 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: JarExplorer.java    From jar-explorer with 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 #2
Source File: AttributeOrderEditPanel.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
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 #3
Source File: CanYouQueryFromRenameTest.java    From netbeans with 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 #4
Source File: L1R2ButtonPanel.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #5
Source File: TestObject.java    From jdk8u_jdk with 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 #6
Source File: ToolBarDemo2.java    From marathonv5 with 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 #7
Source File: FormEditorOperatorTest.java    From netbeans with 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 #8
Source File: SnapApp.java    From snap-desktop with 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 #9
Source File: RemotePrinterStatusRefresh.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 #10
Source File: BoundingBoxValidator.java    From importer-exporter with 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 #11
Source File: AttributeFileValueCellEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #12
Source File: ImageViewer.java    From netbeans with 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 #13
Source File: ButtonDialog.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #14
Source File: JSFConfigurationPanelVisual.java    From netbeans with 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 #15
Source File: AntActionInstance.java    From netbeans with 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 #16
Source File: ActionProviderSupport.java    From netbeans with 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 #17
Source File: JPanelForTree.java    From freeinternals with 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 #18
Source File: Test7024235.java    From TencentKona-8 with 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 #19
Source File: Test7024235.java    From jdk8u60 with 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 #20
Source File: ReportRequirementsPanel.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
private JButton createColonyButton(Colony colony, String info, boolean headline) {
    String text = colony.getName() + info;
    JButton button = Utility.getLinkButton(text, null, colony.getId());
    if (headline) {
        button.setFont(FontLibrary.createCompatibleFont(text,
            FontLibrary.FontType.HEADER, FontLibrary.FontSize.SMALL));
    }
    button.addActionListener(this);
    return button;
}
 
Example #21
Source File: FileChooserDemo.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
WizardDialog(JFrame frame, boolean modal) {
    super(frame, "Embedded JFileChooser Demo", modal);

    cardLayout = new CardLayout();
    cardPanel = new JPanel(cardLayout);
    getContentPane().add(cardPanel, BorderLayout.CENTER);

    messageLabel = new JLabel("", JLabel.CENTER);
    cardPanel.add(chooser, "fileChooser");
    cardPanel.add(messageLabel, "label");
    cardLayout.show(cardPanel, "fileChooser");
    chooser.addActionListener(this);

    JPanel buttonPanel = new JPanel();
    backButton = new JButton("< Back");
    nextButton = new JButton("Next >");
    closeButton = new JButton("Close");

    buttonPanel.add(backButton);
    buttonPanel.add(nextButton);
    buttonPanel.add(closeButton);

    getContentPane().add(buttonPanel, BorderLayout.SOUTH);

    backButton.setEnabled(false);
    getRootPane().setDefaultButton(nextButton);

    backButton.addActionListener(this);
    nextButton.addActionListener(this);
    closeButton.addActionListener(this);

    pack();
    setLocationRelativeTo(frame);
}
 
Example #22
Source File: IOObjectCacheEntryPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new {@link IOObjectCacheEntryPanel}.
 *
 * @param icon
 *            The {@link Icon} associated with the entry's type.
 * @param entryType
 *            Human readable representation of the entry's type (e.g., 'Data Table').
 * @param openAction
 *            The action to be performed when clicking in the entry.
 * @param removeAction
 *            An action triggering the removal of the entry.
 */
public IOObjectCacheEntryPanel(Icon icon, String entryType, Action openAction, Action removeAction) {
	super(ENTRY_LAYOUT);

	this.openAction = openAction;

	// add icon label
	JLabel iconLabel = new JLabel(icon);
	add(iconLabel, ICON_CONSTRAINTS);

	// add object type label
	JLabel typeLabel = new JLabel(entryType);
	typeLabel.setMaximumSize(new Dimension(MAX_TYPE_WIDTH, 24));
	typeLabel.setPreferredSize(typeLabel.getMaximumSize());
	typeLabel.setToolTipText(entryType);
	add(typeLabel, TYPE_CONSTRAINTS);

	// add link button performing the specified action, the label displays the entry's key name
	LinkLocalButton openButton = new LinkLocalButton(openAction);
	openButton.setMargin(new Insets(0, 0, 0, 0));
	add(openButton, KEY_CONSTRAINTS);

	// add removal button
	JButton removeButton = new JButton(removeAction);
	removeButton.setBorderPainted(false);
	removeButton.setOpaque(false);
	removeButton.setMinimumSize(buttonSize);
	removeButton.setPreferredSize(buttonSize);
	removeButton.setContentAreaFilled(false);
	removeButton.setText(null);
	add(removeButton, REMOVE_BUTTON_CONSTRAINTS);

	// register mouse listeners
	addMouseListener(hoverMouseListener);
	iconLabel.addMouseListener(dispatchMouseListener);
	typeLabel.addMouseListener(dispatchMouseListener);
	openButton.addMouseListener(dispatchMouseListener);
	removeButton.addMouseListener(dispatchMouseListener);
}
 
Example #23
Source File: PreviewValueCellEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
public PreviewValueCellEditor(ParameterTypePreview type) {
	this.type = type;
	button = new JButton("Show Preview...");
	button.setToolTipText(type.getDescription());
	button.addActionListener(new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent e) {
			buttonPressed();
		}
	});
}
 
Example #24
Source File: MainToolBar.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void jButton_PanActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.mapView.setMouseTool(MouseTools.Pan);
    if (this.mapLayout != null) {
        this.mapLayout.setMouseMode(MouseMode.Map_Pan);
    }

    setCurrentTool((JButton) evt.getSource());
}
 
Example #25
Source File: MyWindowUtil.java    From gameserver with Apache License 2.0 5 votes vote down vote up
public static JDialog getCenterDialog(int width, int height, 
		JComponent panel, JButton okButton) {
	
	JDialog dialog = new JDialog();
dialog.setLayout(new MigLayout("wrap 1", "[100%]"));
dialog.add(panel, "width 100%, height 90%, grow");
if ( okButton != null ) {
	dialog.add(okButton, "align center");
}
dialog.setSize(width, height);
Point cpoint = WindowUtils.getPointForCentering(dialog);
dialog.setLocation(cpoint);
dialog.setModal(true);
return dialog;
}
 
Example #26
Source File: GrabOnUnfocusableToplevel.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    Robot r = Util.createRobot();
    JWindow w = new JWindow();
    w.setSize(100, 100);
    w.setVisible(true);
    Util.waitForIdle(r);

    final JPopupMenu menu = new JPopupMenu();
    JButton item = new JButton("A button in popup");

    menu.add(item);

    w.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
            menu.show(me.getComponent(), me.getX(), me.getY());

            System.out.println("Showing menu at " + menu.getLocationOnScreen() +
                               " isVisible: " + menu.isVisible() +
                               " isValid: " + menu.isValid());
            }
        });

    Util.clickOnComp(w, r);
    Util.waitForIdle(r);

    if (!menu.isVisible()) {
        throw new RuntimeException("menu was not shown");
    }

    menu.hide();
    System.out.println("Test passed.");
}
 
Example #27
Source File: VideoFilterDialog.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected Component createContents() {
	JPanel buttons = new JPanel();
	buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
	buttons.add(Box.createHorizontalGlue());
	buttons.add(new JButton(cancelAction()));
	buttons.add(new JButton(submitAction("Apply")));

	JPanel contents = new JPanel(new BorderLayout());
	contents.add(form.getComponent(), BorderLayout.CENTER);
	contents.add(buttons, BorderLayout.SOUTH);
	return contents;
}
 
Example #28
Source File: Test6348456.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init() {
    JButton button = new JButton("Swap models");
    button.addActionListener(this);

    this.chooser = new JColorChooser(Color.RED);
    this.chooser.setSelectionModel(WHITE);

    add(BorderLayout.NORTH, button);
    add(BorderLayout.CENTER, this.chooser);
}
 
Example #29
Source File: InputContextMemoryLeakTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example #30
Source File: ShowTextDialog.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
private void addActions(JButton okButton) {
	okButton.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			ShowTextDialog.this.dispose();
		}
	});
}