Java Code Examples for javax.swing.JButton#setEnabled()

The following examples show how to use javax.swing.JButton#setEnabled() . 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: HeadRevisionPicker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({
    "ACSD_HeadRevisionPicker_Cancel=Cancel",
    "CTL_HeadRevisionPicker_Cancel=Cancel",
    "ACSD_HeadRevisionPicker_Select=Select",
    "CTL_HeadRevisionPicker_Select=Select"
})
public HeadRevisionPicker(File repository, File [] roots) {
    panel = new RevisionsPanel(repository, roots);
    okButton = new JButton(Bundle.CTL_HeadRevisionPicker_Select());
    okButton.getAccessibleContext().setAccessibleDescription(Bundle.ACSD_HeadRevisionPicker_Select());
    cancelButton = new JButton(Bundle.CTL_HeadRevisionPicker_Cancel());
    cancelButton.getAccessibleContext().setAccessibleDescription(Bundle.ACSD_HeadRevisionPicker_Cancel());
    okButton.setEnabled(false);
    panel.addPropertyChangeListener(this);
    panel.loadRevisions();
}
 
Example 2
Source File: ImportAppBuilder.java    From raccoon4 with Apache License 2.0 6 votes vote down vote up
public ImportAppBuilder() {
	scan = new JButton(loadIcon("/icons/famfam/icons/folder_magnify.png"));
	scan.setToolTipText(Messages.getString(ID + ".scan.short_description"));
	imprt = new JButton(loadIcon("/icons/famfam/icons/folder_add.png"));
	imprt.setToolTipText(Messages.getString(ID + ".imprt.short_description"));
	list = new JList<Candidate>();
	profile = new JComboBox<PlayProfile>();
	progress = new JTextField();
	groupsPanel = new GroupsPanel();
	progress.setEditable(false);
	titleStrip = new TitleStrip(Messages.getString(ID
			.concat(".titlestrip.title")), Messages.getString(ID
			.concat(".titlestrip.subtitle")), new ImageIcon(getClass().getResource(
			"/icons/appicon.png")));
	progress.setText(Messages.getString(ID.concat(".howto")));
	imprt.setEnabled(false);
}
 
Example 3
Source File: AbstractPersistentPayloadGeneratorUIPanel.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
protected JButton createSaveButton() {
    JButton saveButton = new JButton(SAVE_BUTTON_LABEL);
    saveButton.setToolTipText(SAVE_BUTTON_TOOL_TIP);
    saveButton.setEnabled(false);
    saveButton.setIcon(
            DisplayUtils.getScaledIcon(
                    new ImageIcon(
                            AbstractPersistentPayloadGeneratorUIPanel.class.getResource(
                                    "/resource/icon/16/096.png"))));
    saveButton.addActionListener(
            new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    T2 payloadGenerator = getPayloadGenerator();
                    if (payloadGenerator != null) {
                        Path file = getFile();
                        if (file != null) {
                            saveToFile(payloadGenerator, file);
                        }
                    }
                }
            });
    return saveButton;
}
 
Example 4
Source File: StartScreen.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
private void addControlsButton(Preferences preferences) {
	JButton btnControlsGame = JButtonFactory.createButton("Controls", IconUtils.getControlsIcon(), imageInfoReader, soundIdReader);
	btnControlsGame.setHorizontalAlignment(SwingConstants.LEFT);
	btnControlsGame.setHorizontalTextPosition(SwingConstants.RIGHT);
	btnControlsGame.setToolTipText("View and change game controls");
	btnControlsGame.setEnabled(true);
	btnControlsGame.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			ControlsDialog controlsDialog = new ControlsDialog(keyBindings, imageInfoReader, soundIdReader, musicPlayer);
			controlsDialog.showMe();
			keyBindings.saveSettings(preferences);
			preferences.putBoolean(PLAY_SOUNDS, soundIdReader.isEnabled());
			preferences.putBoolean(PLAY_MUSIC, musicPlayer.isEnabled());
		}
	});
	frame.addComponent(btnControlsGame);
	SwingUtils.setBoundsAndCenterHorizontally(btnControlsGame, BUTTON_LEFT, 290, BUTTON_WIDTH, BUTTON_HEIGHT);
}
 
Example 5
Source File: FileSelector.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form RootSelectorPanel */
public FileSelector(String text, String title, HelpCtx helpCtx, Preferences pref) {
    this.text = text;
    this.title = title;
    this.helpCtx = helpCtx;
    this.pref = pref;

    initComponents();

    filesList.addListSelectionListener(this);

    dialogDescriptor = new DialogDescriptor(this, title);

    okButton = new JButton(org.openide.util.NbBundle.getMessage(FileSelector.class, "CTL_FileSelector_Select"));
    okButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FileSelector.class, "CTL_FileSelector_Select"));
    okButton.setEnabled(false);
    cancelButton = new JButton(org.openide.util.NbBundle.getMessage(FileSelector.class, "CTL_FileSelector_Cancel"));                                      // NOI18N
    cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FileSelector.class, "CTL_FileSelector_Cancel"));    // NOI18N
    dialogDescriptor.setOptions(new Object[] {okButton, cancelButton});

    dialogDescriptor.setModal(true);
    dialogDescriptor.setHelpCtx(new HelpCtx(this.getClass()));
    dialogDescriptor.setValid(false);
}
 
Example 6
Source File: Export.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Export(File fromFile, boolean localChanges) {
    
    this.fromFile = fromFile;
    
    panel = new ExportPanel();

    panel.scanCheckBox.setSelected(SvnModuleConfig.getDefault().getPreferences().getBoolean(SCAN_AFTER_EXPORT, false));
    panel.exportFromTextField.setText(fromFile.getAbsolutePath());
    panel.browseToFolderButton.addActionListener(this);
    panel.exportToTextField.getDocument().addDocumentListener(this);

    panel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(Export.class, "CTL_ExportDialog_Title"));                   // NOI18N

    okButton = new JButton(NbBundle.getMessage(Export.class, "CTL_Export"));
    okButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(Export.class, "CTL_Export"));
    cancelButton = new JButton(NbBundle.getMessage(Export.class, "CTL_Cancel"));                                      // NOI18N
    cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(Export.class, "CTL_Cancel"));    // NOI18N

    dialogDescriptor =
            new DialogDescriptor(
                panel,
                NbBundle.getMessage(Export.class, "CTL_ExportDialog_Title"),
                true,
                new Object[]{okButton, cancelButton},
                okButton,
                DialogDescriptor.DEFAULT_ALIGN,
                null,
                null);
    okButton.setEnabled(false);

    Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
    dialog.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(Export.class, "CTL_ExportDialog_Title"));                // NOI18N

    validateUserInput();
}
 
Example 7
Source File: BranchSelector.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "BranchSelector.okButton.text=&OK",
    "BranchSelector.title=Select Branch"
})
public boolean open () {
    okButton = new JButton();
    org.openide.awt.Mnemonics.setLocalizedText(okButton, Bundle.BranchSelector_okButton_text());
    dd = new DialogDescriptor(panel, Bundle.BranchSelector_title(), true,
            new Object[] { okButton, DialogDescriptor.CANCEL_OPTION }, okButton,
            DialogDescriptor.DEFAULT_ALIGN, null, null);
    revisionPicker.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange (PropertyChangeEvent evt) {
            if (evt.getPropertyName() == RevisionDialogController.PROP_VALID) {
                setRevisionValid(Boolean.TRUE.equals(evt.getNewValue()));
            } else if (evt.getPropertyName() == RevisionDialogController.PROP_REVISION_ACCEPTED) {
                if (dd.isValid()) {
                    okButton.doClick();
                }
            }
        }
    });
    Dialog d = DialogDisplayer.getDefault().createDialog(dd);
    okButton.setEnabled(false);
    d.setVisible(true);
    return okButton == dd.getValue();
}
 
Example 8
Source File: TutorialBrowser.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
private Component createFooterPanel() {
	JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 5, 5));
	buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

	previousStepButton = new JButton();
	previousStepButton.setAction(new ResourceAction("tutorial_browser.previous_step") {

		private static final long serialVersionUID = 1L;

		@Override
		public void loggedActionPerformed(ActionEvent e) {
			ActionStatisticsCollector.INSTANCE.log(ActionStatisticsCollector.TYPE_GETTING_STARTED,
					"tutorial:" + selectedTutorial.getIdentifier(), "step_" + (stepIndex + 1) + "_previous");
			displayStep(--stepIndex);
		}
	});
	previousStepButton.setEnabled(false);
	buttonPanel.add(previousStepButton);

	nextStepButton = new NextStepButton();
	nextStepButton.setEnabled(false);
	nextStepButton.setHorizontalTextPosition(SwingConstants.LEFT);
	buttonPanel.add(nextStepButton);

	JPanel footer = new JPanel(new BorderLayout());
	footer.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Colors.TAB_BORDER));
	footer.add(buttonPanel, BorderLayout.CENTER);

	return footer;
}
 
Example 9
Source File: BranchPicker.java    From netbeans with Apache License 2.0 5 votes vote down vote up
boolean openDialog () {
    final JButton okButton = new JButton();
    Mnemonics.setLocalizedText(okButton, NbBundle.getMessage(BranchPicker.class, "LBL_BranchPicker.okButton.text")); //NOI18N
    DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(BranchPicker.class, "LBL_BranchPicker.title"), //NOI18N
            true, new Object[] { okButton, DialogDescriptor.CANCEL_OPTION }, okButton, DialogDescriptor.DEFAULT_ALIGN, new HelpCtx(BranchPicker.class), null);
    okButton.setEnabled(false);
    Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
    ListSelectionListener list = new ListSelectionListener() {
        @Override
        public void valueChanged (ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                String selected = (String) panel.lstBranches.getSelectedValue();
                selectedPath = null;
                if (!FORBIDDEN_SELECTION.contains(selected)) {
                    selectedPath = selected;
                }
                okButton.setEnabled(selectedPath != null);
            }
        }
    };
    panel.lstBranches.addListSelectionListener(list);
    initializeItems();
    dialog.setVisible(true);
    SvnProgressSupport supp = loadingSupport;
    if (supp != null) {
        supp.cancel();
    }
    panel.lstBranches.removeListSelectionListener(list);
    return dd.getValue() == okButton;
}
 
Example 10
Source File: FileChooserDemo.java    From TencentKona-8 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 11
Source File: ImageableAreaTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowTestDialog(String description,
        String failMessage, Runnable action) {
    final JDialog dialog = new JDialog();
    dialog.setTitle("Test: " + (++testCount));
    dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);
    final JButton testButton = new JButton("Print Table");
    final JButton passButton = new JButton("PASS");
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
    });
    final JButton failButton = new JButton("FAIL");
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        throw new RuntimeException(failMessage);
    });
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        action.run();
        passButton.setEnabled(true);
        failButton.setEnabled(true);
    });
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);
    dialog.pack();
    dialog.setVisible(true);
}
 
Example 12
Source File: SBOLInputDialog.java    From iBioSim with Apache License 2.0 4 votes vote down vote up
private void initGUI() 
{
	JPanel buttonPanel = new JPanel();
	buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
	buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));

	if (registrySelection != null) {
		optionsButton = new JButton("Options");
		optionsButton.addActionListener(actionListener);
		buttonPanel.add(optionsButton);
	}

	buttonPanel.add(Box.createHorizontalStrut(200));
	buttonPanel.add(Box.createHorizontalGlue());
	
	cancelButton = new JButton("Cancel");
	cancelButton.addActionListener(actionListener);
	cancelButton.registerKeyboardAction(actionListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
			JComponent.WHEN_IN_FOCUSED_WINDOW);
	buttonPanel.add(cancelButton);
	
	openVPRGenerator = new JButton("Generate Model");
	openVPRGenerator.addActionListener(actionListener);
	openVPRGenerator.setEnabled(true);
	getRootPane().setDefaultButton(openVPRGenerator);
	buttonPanel.add(openVPRGenerator);
	
	openSBOLDesigner = new JButton("Open SBOLDesigner");
	openSBOLDesigner.addActionListener(actionListener);
	openSBOLDesigner.setEnabled(true);
	getRootPane().setDefaultButton(openSBOLDesigner);
	buttonPanel.add(openSBOLDesigner);
	
	initFormPanel(builder);

	JComponent formPanel = builder.build();
	formPanel.setAlignmentX(LEFT_ALIGNMENT);

	Box topPanel = Box.createVerticalBox();
	String message = initMessage();
	if (message != null) {
		JPanel messageArea = new JPanel();
		messageArea.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6),
				BorderFactory.createEtchedBorder()));
		messageArea.setAlignmentX(LEFT_ALIGNMENT);
		messageArea.add(new JLabel("<html>" + message.replace("\n", "<br>") + "</html>"));
		topPanel.add(messageArea);
	}
	topPanel.add(formPanel);

	JComponent mainPanel = initMainPanel();

	JPanel contentPane = new JPanel(new BorderLayout());
	contentPane.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
	contentPane.add(topPanel, BorderLayout.NORTH);
	if (mainPanel != null) {
		contentPane.add(mainPanel, BorderLayout.CENTER);
	}
	contentPane.add(buttonPanel, BorderLayout.SOUTH);

	setContentPane(contentPane);

	initFinished();

	if (registrySelection != null) {
		registryChanged();
	}

	pack();
	setLocationRelativeTo(getOwner());
}
 
Example 13
Source File: TogglePanel.java    From sr201 with MIT License 4 votes vote down vote up
private void enableButtons() {
	for (final JButton but : butStates.values()) {
		but.setEnabled(true);
	}
}
 
Example 14
Source File: DlgAttrsBug.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void doTest(Runnable action) {
    String description
            = " Visual inspection of print dialog is required.\n"
            + " A print dialog will be shown.\n "
            + " Please verify Copies 5 is selected.\n"
            + " Also verify, Page Range is selected with "
            + " from page 3 and to Page 4.\n"
            + " If ok, press PASS else press FAIL";

    final JDialog dialog = new JDialog();
    dialog.setTitle("printSelectionTest");
    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);
    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    final JButton failButton = new JButton("FAIL");
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail();
    });
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        action.run();
        passButton.setEnabled(true);
        failButton.setEnabled(true);
    });
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);
    dialog.pack();
    dialog.setVisible(true);
}
 
Example 15
Source File: WrongPaperForBookPrintingTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void createAndShowTestDialog() {
    String description =
        " To run this test it is required to have a virtual PDF\r\n" +
        " printer or any other printer supporting A5 paper size.\r\n" +
        "\r\n" +
        " 1. Verify that NOT A5 paper size is set as default for the\r\n" +
        " printer to be used.\r\n" +
        " 2. Click on \"Start Test\" button.\r\n" +
        " 3. In the shown print dialog select the printer and click\r\n" +
        " on \"Print\" button.\r\n" +
        " 4. Verify that a page with a drawn rectangle is printed on\r\n" +
        " a paper of A5 size which is (5.8 x 8.3 in) or\r\n" +
        " (148 x 210 mm).\r\n" +
        "\r\n" +
        " If the printed page size is correct, click on \"PASS\"\r\n" +
        " button, otherwise click on \"FAIL\" button.";

    final JDialog dialog = new JDialog();
    dialog.setTitle("WrongPaperForBookPrintingTest");
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            dialog.dispose();
            fail("Main dialog was closed.");
        }
    });

    final JLabel testTimeoutLabel = new JLabel(String.format(
        "Test timeout: %s", convertMillisToTimeStr(testTimeout)));
    final long startTime = System.currentTimeMillis();
    final Timer timer = new Timer(0, null);
    timer.setDelay(1000);
    timer.addActionListener((e) -> {
        int leftTime = testTimeout - (int) (System.currentTimeMillis() - startTime);
        if ((leftTime < 0) || testFinished) {
            timer.stop();
            dialog.dispose();
        }
        testTimeoutLabel.setText(String.format(
            "Test timeout: %s", convertMillisToTimeStr(leftTime)));
    });
    timer.start();

    JTextArea textArea = new JTextArea(description);
    textArea.setEditable(false);

    final JButton testButton = new JButton("Start Test");
    final JButton passButton = new JButton("PASS");
    final JButton failButton = new JButton("FAIL");
    testButton.addActionListener((e) -> {
        testButton.setEnabled(false);
        new Thread(() -> {
            try {
                doTest();

                SwingUtilities.invokeLater(() -> {
                    passButton.setEnabled(true);
                    failButton.setEnabled(true);
                });
            } catch (Throwable t) {
                t.printStackTrace();
                dialog.dispose();
                fail("Exception occurred in a thread executing the test.");
            }
        }).start();
    });
    passButton.setEnabled(false);
    passButton.addActionListener((e) -> {
        dialog.dispose();
        pass();
    });
    failButton.setEnabled(false);
    failButton.addActionListener((e) -> {
        dialog.dispose();
        fail("Size of a printed page is wrong.");
    });

    JPanel mainPanel = new JPanel(new BorderLayout());
    JPanel labelPanel = new JPanel(new FlowLayout());
    labelPanel.add(testTimeoutLabel);
    mainPanel.add(labelPanel, BorderLayout.NORTH);
    mainPanel.add(textArea, BorderLayout.CENTER);
    JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(testButton);
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.add(mainPanel);

    dialog.pack();
    dialog.setVisible(true);
}
 
Example 16
Source File: FileSearchAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Dialog createDialog( final FileSearchPanel panel) {
    openBtn = new JButton();
    Mnemonics.setLocalizedText(openBtn, NbBundle.getMessage(FileSearchAction.class, "CTL_Open"));
    openBtn.getAccessibleContext().setAccessibleDescription(openBtn.getText());
    openBtn.setEnabled( false );

    final Object[] buttons = new Object[] { openBtn, DialogDescriptor.CANCEL_OPTION };

    String title = NbBundle.getMessage(FileSearchAction.class, "MSG_FileSearchDlgTitle");
    DialogDescriptor dialogDescriptor = new DialogDescriptor(
            panel,
            title,
            true,
            buttons,
            openBtn,
            DialogDescriptor.DEFAULT_ALIGN,
            HelpCtx.DEFAULT_HELP,
            new DialogButtonListener(panel));
    dialogDescriptor.setClosingOptions(buttons);

    Dialog d = DialogDisplayer.getDefault().createDialog(dialogDescriptor);
    d.getAccessibleContext().setAccessibleName(NbBundle.getMessage(FileSearchAction.class, "AN_FileSearchDialog"));
    d.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(FileSearchAction.class, "AD_FileSearchDialog"));

    // Set size
    d.setPreferredSize( new Dimension(  FileSearchOptions.getWidth(),
                                             FileSearchOptions.getHeight() ) );

    // Center the dialog after the size changed.
    Rectangle r = Utilities.getUsableScreenBounds();
    int maxW = (r.width * 9) / 10;
    int maxH = (r.height * 9) / 10;
    Dimension dim = d.getPreferredSize();
    dim.width = Math.min(dim.width, maxW);
    dim.height = Math.min(dim.height, maxH);
    initialDimension = dim;
    d.setBounds(Utilities.findCenterBounds(dim));
    d.addWindowListener(new WindowAdapter() {
        public @Override void windowClosed(WindowEvent e) {
            cleanup(false);
        }
    });

    return d;
}
 
Example 17
Source File: ResetMostRecentFocusOwnerTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void start() {

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent e) {
            System.err.println(e);
        }
    }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);

    boolean gained = false;
    final Robot robot = Util.createRobot();

    JFrame frame1 = new JFrame("Main Frame");
    final JButton b1 = new JButton("button1");
    frame1.add(b1);
    frame1.pack();
    frame1.setLocation(0, 300);

    Util.showWindowWait(frame1);

    final JFrame frame2 = new JFrame("Test Frame");
    final JButton b2 = new JButton("button2");
    frame2.add(b2);
    frame2.pack();
    frame2.setLocation(300, 300);

    b2.setEnabled(false);
    b2.requestFocus();

    Util.showWindowWait(frame2);

    robot.delay(500);

    //
    // It's expeced that the focus is restored to <button1>.
    // If not, click <button1> to set focus on it.
    //
    if (!b1.hasFocus()) {
        gained = Util.trackFocusGained(b1, new Runnable() {
            public void run() {
                Util.clickOnComp(b1, robot);
            }
        }, 5000, false);

        if (!gained) {
            throw new RuntimeException("Unexpected state: focus is not on <button1>");
        }
    }

    robot.delay(500);

    //
    // Click <button2>, check that focus is set on the parent frame.
    //
    gained = false;
    gained = Util.trackFocusGained(frame2, new Runnable() {
        public void run() {
            Util.clickOnComp(b2, robot);
        }
    }, 5000, false);

    if (!gained) {
        throw new RuntimeException("Test failed: focus wasn't set to <frame2>");
    }

    System.out.println("Test passed.");
}
 
Example 18
Source File: KernelControlPanel.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void setControlButtonsEnabled(boolean b) {
    for (JButton next : controlButtons) {
        next.setEnabled(b);
    }
}
 
Example 19
Source File: VolatileImageConfigurationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void initComponents() {
    /* Create the text area with steps to execute the test */
    String description
            = "\n Volatile Image Configuration Update Test.\n"
            + " 1. The test displays scale values of component and the"
            + " underlying graphics device configuration.\n"
            + " 2. Kindly change the display's DPI settings from OS"
            + " control panel and observe the application.\n"
            + " 3. Select Pass if the scale values for both component & "
            + "underlying device configuration are updated as per the "
            + "\ndisplay's DPI value.\n";
    infoTextArea = new JTextArea(description);

    /* Create the test panel where user will observe the drawing */
    testPanel = new DisplayPanel();

    /* Create the buttons with event listeners */
    passButton = new JButton("Pass");
    passButton.setActionCommand("Pass");
    passButton.setEnabled(true);
    passButton.addActionListener(this);

    failButton = new JButton("Fail");
    failButton.setActionCommand("Fail");
    failButton.setEnabled(true);
    failButton.addActionListener(this);

    /* Add the buttons to a separate panel with flowlayout */
    buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.add(passButton);
    buttonPanel.add(failButton);

    /* Add all the created components to the master frame */
    setLayout(new BorderLayout(10, 10));
    add(infoTextArea, BorderLayout.NORTH);
    add(buttonPanel, BorderLayout.SOUTH);
    add(testPanel, BorderLayout.CENTER);

    /* Set the dimensions */
    setSize(TEST_WIDTH, TEST_HEIGHT);
}
 
Example 20
Source File: AccountsPanel.java    From btdex with GNU General Public License v3.0 4 votes vote down vote up
public AccountsPanel(Main main) {
	super(new BorderLayout());

	this.main = main;

	table = new JTable(model = new DefaultTableModel(COLUMN_NAMES, 0));
	for (int i = 0; i < COLUMN_NAMES.length; i++) {
		table.getColumnModel().getColumn(i).setHeaderValue(tr(COLUMN_NAMES[i]));
	}
	table.setRowHeight(table.getRowHeight()+7);
	table.setPreferredScrollableViewportSize(new Dimension(400, 200));
	table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	table.getSelectionModel().addListSelectionListener(this);

	left = new JPanel(new BorderLayout());
	right = new JPanel();
	right.setVisible(false);
	right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS));

	left.setBorder(BorderFactory.createTitledBorder(tr("acc_your_accounts")));
	right.setBorder(BorderFactory.createTitledBorder(tr("acc_account_details")));

	JScrollPane scrollPane = new JScrollPane(table);
	table.setFillsViewportHeight(true);

	// Center header and all columns
	DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
	centerRenderer.setHorizontalAlignment( JLabel.CENTER );
	for (int i = 0; i < table.getColumnCount(); i++) {
		table.getColumnModel().getColumn(i).setCellRenderer( centerRenderer );			
	}
	JTableHeader jtableHeader = table.getTableHeader();
	DefaultTableCellRenderer rend = (DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer();
	rend.setHorizontalAlignment(JLabel.CENTER);
	jtableHeader.setDefaultRenderer(rend);

	table.setAutoCreateColumnsFromModel(false);
	table.getColumnModel().getColumn(COL_NAME).setPreferredWidth(200);
	table.getColumnModel().getColumn(COL_MARKET).setPreferredWidth(20);

	JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
	left.add(buttonPane, BorderLayout.PAGE_END);

	addButton = new JButton(tr("acc_add_button"));
	removeButton = new JButton(tr("acc_remove_button"));
	removeButton.setEnabled(false);

	addButton.addActionListener(this);
	removeButton.addActionListener(this);

	buttonPane.add(addButton);
	buttonPane.add(removeButton);

	marketComboBox = new JComboBox<Market>();
	for(Market m : Markets.getMarkets()) {
		if(m.getTokenID()!=null)
			continue;
		marketComboBox.addItem(m);
	}
	marketComboBox.addActionListener(this);

	JPanel topPanel = new JPanel(new SpringLayout());
	topPanel.add(new Desc(tr("main_market"), marketComboBox), BorderLayout.LINE_START);
	topPanel.add(new Desc(tr("acc_alias"), nameField = new JTextField()), BorderLayout.CENTER);
	SpringUtilities.makeCompactGrid(topPanel, 1, 2, 0, 0, PAD, PAD);
	right.add(topPanel);

	formPanel = new JPanel(new SpringLayout());
	//		JScrollPane formScroll = new JScrollPane(formPanel);
	//		right.add(formScroll);
	right.add(formPanel);

	cancelButton = new JButton(tr("dlg_cancel"));
	okButton = new JButton(tr("dlg_ok"));

	cancelButton.addActionListener(this);
	okButton.addActionListener(this);
	rightButtonPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
	rightButtonPane.add(cancelButton);
	rightButtonPane.add(okButton);
	right.add(rightButtonPane);

	add(left, BorderLayout.LINE_START);
	JPanel rightContainer = new JPanel(new BorderLayout());
	rightContainer.add(right, BorderLayout.PAGE_START);
	add(rightContainer, BorderLayout.CENTER);

	left.add(scrollPane, BorderLayout.CENTER);	

	loadAccounts();
}