Java Code Examples for javax.swing.JFrame.revalidate()

The following are Jave code examples for showing how to use revalidate() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: my-diploma-work   File: IngredientsFrame.java   View Source Code Vote up 7 votes
public void addCheckBoxToPanel(Food food) {
    JFrame frame = this;
    jPanel2.setLayout(new GridLayout(0, 4));
    final JCheckBox box = new JCheckBox(food.getFood());
    box.setActionCommand(String.valueOf(food.getId()));
    box.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (box.isSelected()) {
                jTextArea1.append(box.getText() + "\n");
                selectedFoodIds.add(Integer.parseInt(box.getActionCommand()));
            }
        }
    });
    jPanel2.add(box);
    frame.revalidate();
    frame.repaint();
}
 
Example 2
Project: SWEngProject   File: Menu.java   View Source Code Vote up 6 votes
private void resetLoginUI(int x, int y, JFrame f, JPanel loginPanel, JLabel logoLabel,
		JTextField usernameTextField, JTextField passwordTextField,
		JButton signInButton, JButton logInButton, JButton settingsButton,
		JLabel bgLabel) {

	int i = y - 520;

	f.remove(loginPanel);
	f.setSize(x, y);
	f.revalidate();

	loginPanel.setBounds(0, 0, x, y);
	logoLabel.setBounds(x / 2 - 200, i / 2, 400, 190);
	usernameTextField.setBounds(x / 2 - 200, i / 2 + 200, 400, 100);
	passwordTextField.setBounds(x / 2 - 200, i / 2 + 310, 400, 100);
	signInButton.setBounds(x / 2 - 200, i / 2 + 420, 195, 100);
	logInButton.setBounds(x / 2 + 5, i / 2 + 420, 195, 100);
	settingsButton.setBounds(x - 70, 10, 60, 60);
	bgLabel.setBounds(0, 0, x, y);

	f.add(loginPanel);
	f.revalidate();
	f.repaint();

}
 
Example 3
Project: SWEngProject   File: MainMenu.java   View Source Code Vote up 6 votes
private void resetUIMainMenu(int x, int y, JFrame f, JPanel mainMenuPanel, JLabel bgLabel,
		JLabel logoLabel, JButton newGameButton, JButton optionsButton,
		JButton instrButton, JButton exitButton) {
	
	int i = y - 520;
	
	f.remove(mainMenuPanel);
	f.setSize(x, y);
	f.revalidate();
	
	mainMenuPanel.setBounds(0, 0, x, y);
	bgLabel.setBounds(0, 0, x, y);
	logoLabel.setBounds(x / 2 - 200, i / 2, 400, 190);
	newGameButton.setBounds(x / 2 - 200, i / 2 + 200, 400, 70);
	optionsButton.setBounds(x / 2 - 200, i / 2 + 280, 400, 70);
	instrButton.setBounds(x / 2 - 200, i / 2 + 360, 400, 70);
	exitButton.setBounds(x / 2 - 200, i / 2 + 440, 400, 70);		
	
	f.add(mainMenuPanel);
	f.revalidate();
	f.repaint();

}
 
Example 4
Project: incubator-netbeans   File: EditorOnlyDisplayer.java   View Source Code Vote up 5 votes
private boolean switchCurrentEditor() {
    final TopComponent tc = TopComponent.getRegistry().getActivated();
    if( null == tc || !TopComponentTracker.getDefault().isEditorTopComponent( tc ) )
        return false;

    final WindowManagerImpl wmi = WindowManagerImpl.getInstance();
    final JFrame mainWnd = ( JFrame ) wmi.getMainWindow();
    if( SwingUtilities.isDescendingFrom( tc, mainWnd.getContentPane() ) )
        return true;
    JPanel panel = new JPanel( new BorderLayout() );
    panel.add( tc, BorderLayout.CENTER  );
    try {
        mainWnd.setContentPane( panel );
    } catch( IndexOutOfBoundsException e ) {
        Logger.getLogger(EditorOnlyDisplayer.class.getName()).log(Level.INFO, "Error while switching current editor.", e);
        //#245541 - something is broken in the component hierarchy, let's try restoring to the default mode
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                cancel(false);
            }
        });
    }
    mainWnd.invalidate();
    mainWnd.revalidate();
    mainWnd.repaint();
    SwingUtilities.invokeLater( new Runnable() {
        @Override
        public void run() {
            tc.requestFocusInWindow();
        }
    });
    return true;
}
 
Example 5
Project: SWEngProject   File: Instructions.java   View Source Code Vote up 4 votes
public Instructions(JFrame f, int frameBoundX, int frameBoundY) {
	
	// Font
	InputStream is = Menu.class.getResourceAsStream("Cheap Potatoes.ttf");
	try {
		font = Font.createFont(Font.TRUETYPE_FONT, is);
	} catch (FontFormatException | IOException e1) {
		// TODO Auto-generated catch
		// block
		e1.printStackTrace();
	}
	
	//Main Panel of Instructions Section created here
	JPanel instrPanel = new JPanel();
	instrPanel.setLayout(null);
	setBounds(0,0,frameBoundX, frameBoundY);
	
	//Logo
	JLabel logoLabel = new JLabel("GEOTRIX", SwingConstants.CENTER);
	sizedFont = font.deriveFont(68f);
	logoLabel.setFont(sizedFont);
	logoLabel.setBounds(frameBoundX / 2 - 200, (frameBoundY-520)/ 2, 400, 190);
	
	JButton backButton = new JButton("Back");
	backButton.setBorderPainted(false);
	backButton.setFocusPainted(false);
	backButton.setContentAreaFilled(false);
	sizedFont = font.deriveFont(Font.BOLD, 30f);
	backButton.setFont(sizedFont);
	backButton.setForeground(Color.RED);
	backButton.setBounds(10, 10, 200, 100);
	// when backButton clicked
	backButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			//remove panel
			instrPanel.setVisible(false);
			f.remove(instrPanel);
			new MainMenu(f, frameBoundX, frameBoundY);
		}
	});
	
	//Logo
	JLabel instructionLabel = new JLabel("Arrow keys + Space button", SwingConstants.CENTER);
	sizedFont = font.deriveFont(40f);
	instructionLabel.setFont(sizedFont);
	instructionLabel.setBounds(25, frameBoundY/2 - 100, frameBoundX - 50, 200);
	instrPanel.add(instructionLabel);

	//Background Icon
	String img = "background_revision.jpg";
	ImageIcon imgIc = new ImageIcon(this.getClass().getResource(img));
	
	//Backgroud Label
	JLabel bgLabel = new JLabel(imgIc);
	bgLabel.setBounds(0, 0, frameBoundX, frameBoundY);

	instrPanel.add(backButton);
	instrPanel.add(logoLabel);
	instrPanel.add(bgLabel);
	
	f.add(instrPanel);
	f.revalidate();
	f.setVisible(true);
	
	
}