Java Code Examples for javax.swing.JFrame#requestFocus()

The following examples show how to use javax.swing.JFrame#requestFocus() . 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: OurUtil.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/** Make the frame visible, non-iconized, and focused. */
public static void show(JFrame frame) {
    frame.setVisible(true);
    frame.setExtendedState(frame.getExtendedState() & ~Frame.ICONIFIED);
    frame.requestFocus();
    frame.toFront();
}
 
Example 2
Source File: bug8069348.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {

        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JDesktopPane desktopPane = new JDesktopPane();
        desktopPane.setBackground(DESKTOPPANE_COLOR);

        internalFrame = new JInternalFrame("Test") {

            @Override
            public void paint(Graphics g) {
                super.paint(g);
                g.setColor(FRAME_COLOR);
                g.fillRect(0, 0, getWidth(), getHeight());
            }
        };
        internalFrame.setSize(WIN_WIDTH / 3, WIN_HEIGHT / 3);
        internalFrame.setVisible(true);
        desktopPane.add(internalFrame);

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(desktopPane, BorderLayout.CENTER);
        frame.add(panel);
        frame.setSize(WIN_WIDTH, WIN_HEIGHT);
        frame.setVisible(true);
        frame.requestFocus();
    }
 
Example 3
Source File: SwingUtil.java    From Repeat with Apache License 2.0 5 votes vote down vote up
public static void focus(JFrame frame, Function<Void, Boolean> callBackRender) {
	if (frame.getState() == Frame.ICONIFIED) {
		frame.setState(Frame.NORMAL);
	}

	if (!frame.isVisible()) {
		callBackRender.apply(null);
		frame.setVisible(true);
	}

	frame.requestFocus();
	frame.toFront();
}
 
Example 4
Source File: bug8069348.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void createAndShowGUI() {

        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JDesktopPane desktopPane = new JDesktopPane();
        desktopPane.setBackground(DESKTOPPANE_COLOR);

        internalFrame = new JInternalFrame("Test") {

            @Override
            public void paint(Graphics g) {
                super.paint(g);
                g.setColor(FRAME_COLOR);
                g.fillRect(0, 0, getWidth(), getHeight());
            }
        };
        internalFrame.setSize(WIN_WIDTH / 3, WIN_HEIGHT / 3);
        internalFrame.setVisible(true);
        desktopPane.add(internalFrame);

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(desktopPane, BorderLayout.CENTER);
        frame.add(panel);
        frame.setSize(WIN_WIDTH, WIN_HEIGHT);
        frame.setVisible(true);
        frame.requestFocus();
    }
 
Example 5
Source File: StitchingExplorerPanel.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
private void initLinkExplorer()
{
	// we already should have an instance
	if ( linkExplorer != null )
		return;

	linkExplorer = new LinkExplorerPanel( stitchingResults, (StitchingExplorerPanel< AbstractSpimData< ? >, ? >) this );
	// init the LinkExplorer
	linkFrame = new JFrame( "Link Explorer" );
	linkFrame.add( linkExplorer, BorderLayout.CENTER );
	linkFrame.setSize( linkExplorer.getPreferredSize() );

	linkFrame.addWindowListener( new WindowAdapter()
	{
		@Override
		public void windowClosing(WindowEvent evt)
		{
			setSavedFilteringAndGrouping( null );
			togglePreviewMode(false);
		}
	} );

	linkFrame.pack();
	linkFrame.setVisible( true );
	linkFrame.requestFocus();

	MultiWindowLayoutHelper.moveToScreenFraction( linkFrame, xPosLinkExplorer, yPosLinkExplorer );
}
 
Example 6
Source File: RegularGridPopup.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent e )
{
	if ( panel == null )
	{
		IOFunctions.println( "Panel not set for " + this.getClass().getSimpleName() );
		return;
	}

	/*
	BigDataViewer bdv = panel.bdvPopup().getBDV();
	
	if (bdv == null)
	{
		IOFunctions.println( "BigDataViewer is not open. Please start it to access this funtionality." );
		return;
	}
	*/

	regularGridPanel = new PreviewRegularGridPanel<>( panel );

	JFrame frame = new JFrame( "Regular Grid Options" );
	frame.add( regularGridPanel, BorderLayout.CENTER );
	frame.setSize( regularGridPanel.getPreferredSize() );

	frame.addWindowListener( new WindowAdapter()
	{
		@Override
		public void windowClosing( WindowEvent evt )
		{
			regularGridPanel.quit();
		}
	} );

	
	frame.pack();
	frame.setVisible( true );
	frame.requestFocus();
	
	/*
	for (int i = 0; i < bdv.getViewer().getVisibilityAndGrouping().numSources(); ++i)
	{
		Integer tpId = bdv.getViewer().getState().getCurrentTimepoint();
		SourceState<?> s = bdv.getViewer().getVisibilityAndGrouping().getSources().get( i );
		
		// get manual transform
		AffineTransform3D tAffine = new AffineTransform3D();
		((TransformedSource< ? >)s.getSpimSource()).getFixedTransform( tAffine );
		
		// get old transform
		ViewRegistration vr = panel.getSpimData().getViewRegistrations().getViewRegistration( new ViewId(tpId, i ));
		AffineGet old = vr.getTransformList().get( 1 ).asAffine3D();
		
		// update transform in ViewRegistrations
		AffineTransform3D newTransform = new AffineTransform3D();
		newTransform.set( old.get( 0, 3 ) + tAffine.get( 0, 3 ), 0, 3 );
		newTransform.set( old.get( 1, 3 ) + tAffine.get( 1, 3 ), 1, 3 );
		newTransform.set( old.get( 2, 3 ) + tAffine.get( 2, 3 ), 2, 3 );
		
		ViewTransform newVt = new ViewTransformAffine( "Translation", newTransform );				
		vr.getTransformList().set( 1, newVt );
		vr.updateModel();
		
		// reset manual transform
		((TransformedSource< ? >)s.getSpimSource()).setFixedTransform( new AffineTransform3D() );
		bdv.getViewer().requestRepaint();
	}
	
	panel.bdvPopup().updateBDV();			
	
	*/
}
 
Example 7
Source File: VCardEditor.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
    * Displays a users profile.
    * 
    * @param jid
    *            the jid of the user.
    * @param vcard
    *            the users vcard.
    * @param parent
    *            the parent component, used for location handling.
    */
   public void displayProfile(final BareJid jid, VCard vcard, JComponent parent) {
VCardViewer viewer = new VCardViewer(jid);

final JFrame dlg = new JFrame(Res.getString("title.view.profile.for",
	jid));

avatarLabel = new JLabel();
avatarLabel.setHorizontalAlignment(JButton.RIGHT);
avatarLabel.setBorder(BorderFactory.createBevelBorder(0, Color.white,
	Color.lightGray));

// The user should only be able to close this dialog.
Object[] options = { Res.getString("button.view.profile"),
	Res.getString("close") };
final JOptionPane pane = new JOptionPane(viewer,
	JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,
	options, options[0]);

// mainPanel.add(pane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
// GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5,
// 5, 5), 0, 0));

dlg.setIconImage(SparkRes.getImageIcon(SparkRes.PROFILE_IMAGE_16x16)
	.getImage());

dlg.pack();
dlg.setSize(350, 250);
dlg.setResizable(true);
dlg.setContentPane(pane);
dlg.setLocationRelativeTo(parent);

PropertyChangeListener changeListener = new PropertyChangeListener() {
    @Override
	public void propertyChange(PropertyChangeEvent e) {
	if (pane.getValue() instanceof Integer) {
	    pane.removePropertyChangeListener(this);
	    dlg.dispose();
	    return;
	}
	String value = (String) pane.getValue();
	if (Res.getString("close").equals(value)) {
	    pane.removePropertyChangeListener(this);
	    dlg.dispose();
	} else if (Res.getString("button.view.profile").equals(value)) {
	    pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
	    SparkManager.getVCardManager().viewFullProfile(jid, pane);
	}
    }
};

pane.addPropertyChangeListener(changeListener);

dlg.addKeyListener(new KeyAdapter() {
    @Override
	public void keyPressed(KeyEvent keyEvent) {
	if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) {
	    dlg.dispose();
	}
    }
});

dlg.setVisible(true);
dlg.toFront();
dlg.requestFocus();
   }