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

The following are Jave code examples for showing how to use repaint() 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 6 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: FocusAfterBadEditTest.java   View Source Code Vote up 5 votes
protected void setUp() throws Exception {
    if (setup) return;
    
    try {
        focusWorks = ExtTestCase.canSafelyRunFocusTests();
        if (!focusWorks) {
            return;
        }
        
        tp = new TProperty("Dont set me!", true);
        
        tn = new TNode();
        //            PropUtils.forceRadioButtons=true;
        final PropertySheet ps = new PropertySheet();
        
        //ensure no stored value in preferences:
        ps.setCurrentNode(tn);
        sleep();
        ps.setSortingMode(PropertySheet.UNSORTED);
        
        jf = new JFrame();
        jf.getContentPane().add(ps);
        jf.setLocation(20,20);
        jf.setSize(300, 400);
        new WaitWindow(jf);
        tb = ps.table;
        
        jf.repaint();
        
        
    } catch (Exception e) {
        e.printStackTrace();
        fail("FAILED - Exception thrown "+e.getClass().toString());
    } finally {
        setup = true;
    }
}
 
Example 5
Project: incubator-netbeans   File: PropertyMarkingTest.java   View Source Code Vote up 5 votes
protected void setUp() throws Exception {
    if (setup) return;
    PropUtils.forceRadioButtons=false;
    
    try {
        
        tp = new TProperty("oh", true);
        tp1 = new TProperty2("the", true);
        tp2 = new TProperty2("pretty", true);
        tp3 = new TProperty2("pictures",true);
        tp4 = new TProperty3("I can create",true);
        postSetAction = new PostSetAction();
        
        tn = new TNode();
        
        final PropertySheet ps = new PropertySheet();
        
        //ensure no stored value in preferences:
        ps.setCurrentNode(tn);
        sleep();
        ps.setSortingMode(PropertySheet.UNSORTED);
        
        jf = new JFrame();
        jf.getContentPane().add(ps);
        jf.setLocation(20,20);
        jf.setSize(300, 400);
        new WaitWindow(jf);
        tb = ps.table;
        
        ps.setSortingMode(ps.SORTED_BY_NAMES);
        jf.repaint();
        
        
    } catch (Exception e) {
        e.printStackTrace();
        fail("FAILED - Exception thrown "+e.getClass().toString());
    } finally {
        setup = true;
    }
}
 
Example 6
Project: incubator-netbeans   File: AbstractWindowRunner.java   View Source Code Vote up 5 votes
private void ungrayMainWindow() {
    if (oldGlassPane != null) {
        JFrame jf = (JFrame) WindowManager.getDefault().getMainWindow();
        jf.setGlassPane(oldGlassPane);
        jf.getGlassPane().setVisible(false);          
        jf.invalidate();
        jf.repaint();
    }
}
 
Example 7
Project: incubator-netbeans   File: QueryBuilder.java   View Source Code Vote up 5 votes
private static void doShowBusyCursor(boolean busy) {
    JFrame mainWindow = (JFrame)WindowManager.getDefault().getMainWindow();
    if(busy){
        RepaintManager.currentManager(mainWindow).paintDirtyRegions();
        mainWindow.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        mainWindow.getGlassPane().setVisible(true);
        mainWindow.repaint();
    } else {
        mainWindow.getGlassPane().setVisible(false);
        mainWindow.getGlassPane().setCursor(null);
        mainWindow.repaint();
    }
}
 
Example 8
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 9
Project: jdk8u-jdk   File: DrawBitmaskToSurfaceTest.java   View Source Code Vote up 5 votes
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 10
Project: openjdk-jdk10   File: DrawBitmaskToSurfaceTest.java   View Source Code Vote up 5 votes
public static void main(final String[] args) throws Exception {
    final JFrame frame = new DrawBitmaskToSurfaceTest();
    frame.setBounds(10, 350, 200, 200);
    frame.setVisible(true);

    Thread.sleep(2000);

    System.err.println("Change frame bounds...");
    latch = new CountDownLatch(1);
    frame.setBounds(10, 350, 90, 90);
    frame.repaint();

    try {
        if (latch.getCount() > 0) {
            latch.await();
        }
    } catch (InterruptedException e) {
    }

    frame.dispose();

    if (theError != null) {
        throw new RuntimeException("Test failed.", theError);
    }

    System.err.println("Test passed");
}
 
Example 11
Project: jOthelloT   File: OthelloTournament.java   View Source Code Vote up 5 votes
public void saveGameRecord(JFrame frame, String competidores, PvpScore pvpScore) {
    try {
        frame.validate();
        frame.repaint();            
        Container c = frame.getContentPane();
        c.validate();
        c.repaint();
        BufferedImage im = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
        c.paint(im.getGraphics());
        pvpScore.setGameRecord(im);
    } catch (Exception ex) {
        Logger.getLogger(OthelloTournament.class
                .getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 12
Project: jaer   File: KernelMaker2D.java   View Source Code Vote up 2 votes
public static void plot(float[][] w,Scaling scaling)
    {
        ImageDisplay disp=ImageDisplay.createOpenGLCanvas();
        
        float max=Float.NEGATIVE_INFINITY;
        float min=Float.POSITIVE_INFINITY;
        for (int i=0; i<w.length; i++)
            for (int j=0; j<w[i].length; j++)
            {   max=Math.max(max,w[i][j]);
                min=Math.min(min,w[i][j]);
            }
        
        max=Math.max(max,min+Float.MIN_VALUE);
        
        
        max=Math.abs(max);
        min=Math.abs(min);
        float absmax=Math.max(min,max);
        
        if (scaling==Scaling.FitAboutZero)
        {
            
            max=absmax;
            min=-absmax;
        }
        
        
        final DecimalFormat myFormatter = new DecimalFormat("0.###");
        
        disp.setImageSize(w[0].length,w.length);
        
        disp.setSize(300,300);
        
        disp.setTitleLabel("Range: [ "+myFormatter.format(min)+"   "+myFormatter.format(max)+" ] ");
        
//        disp.setPreferredSize(new Dimension(300,300));
        
        for (int i=0; i<w.length; i++)
            for (int j=0; j<w[i].length; j++)
            {   float val=w[i][j];
                if (val>0)
                    disp.setPixmapRGB(j, i, val/absmax, 0, 0);
                else
                    disp.setPixmapRGB(j, i, 0, 0, -val/absmax);
                
            }
//                disp.setPixmapGray(j,i,(w[i][j]-min)/(max-min));    
        
            
        JFrame frm=new JFrame();
        frm.setSize(new Dimension(400,400));
        
        
        frm.getContentPane().add(disp);
        
        frm.setVisible(true);
        
        frm.repaint();
    }