Background Color change JFrame

I have to change the background color when the result is either too high or low. Program runs great except the background color doesn't change. And before you complain about my code, I hit the "CODE" button before and after my code in here and it does nothing. The videos wouldn't play. So I don't know how to add code correctly.
import java.awt.*;
import java.util.Random;
import javax.swing.*;
public class NumberGuess extends JFrame {
Random rand = new Random ( ) ;
int randomNumber = 1 + rand.nextInt(1000);
int count = 0;
private JFrame panel = new JFrame();
private JFrame panelButtons = new JFrame();
private JFrame panelBottom = new JFrame();
private void compareResult() {
int userInput = Integer.parseInt(tempTextField.getText().trim());
if ( userInput > randomNumber )
resultLabel.setText( "Too High. Try a lower number." );
setBackgroundColor(Color.blue);
private void setBackgroundColor(Color color)
panel.setBackground(color);
panelBottom.setBackground(color);
panelButtons.setBackground(color);

Goofy_1969 wrote:
And before you complain about my code, I hit the "CODE" button before and after my code in here and it does nothing.Well, you did manage to create 2 empty code blocks though.
I know this is New To Java, so I need to be nicer and most of you people don't probably have the intrinsic knowledge of "start tag" and "end tag".
But still. All you need is to put your code between tags and everything will work great.
AND HEY, There's the preview button too! So you can actually try and try and try until it works. It's just that programming is a difficult hobby and if you can't work the code tags, you really need to rethink whether you're ready for something that's actually complicated.
(Also if you're not using the code tags, your code will totally get screwed up and people can't help you even if they wanted to.)
As for your code, try using SwingUtilities.invokeLater(). That's the only way you can modify the GUI when you're not running in the event thread.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Change background color  for JFrame

    hi,
    i want to change background color of JFrame. In my application i didn't create any panels.
    my code like this,
    Frame myFrame = new JFrame ( " Grid Layout Frame ");     
    myFrame.setSize(500,500);     
    myFrame.getContentPane().setBackground(Color.white);
    myFrame.setVisible(true);thanks,
    Balaji

    You don't get a white frame when you run this program?import java.awt.*;
    import javax.swing.*;
    public class junk
         public static void main(String[] args) throws Exception
              JFrame f = new JFrame("Hello");
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.setSize(500,500);
              f.getContentPane().setBackground(Color.white);
              f.setVisible(true);
    }

  • Cell/Background color changes when copying to other Excel 2010 document

    When you copy and paste report cells (e.g. CO report outputted in Office integration, MS Excel) to a new Excel file, the background color changed dramatically (to bright red).
    SAP Theme:  SAP Signature Theme
    Excel 2010
    We tried paste option > match destination formatting but does not help.
    Anyone has similiar problems?  Appreciate any help.

    dear friend,
    you would do:
    1. search SAP Notes;
    2. check out the updates/patches for your MS Office;
    3. replicate it on another computer/another sap user (make sure it is a local issue)
    good luck!

  • Background color changed from white to yellow and =25% changed to %% on email

    I type =25% on my email and sent out, background color changed from white to yellow and =25% changed to %%.

    Try leaving a space after the =
    Thus: = 25%
    Where and when did it change? Did it change inside Thunderbird? Did it change in the Sent folder? Or in a reply to you?
    = and % are used in certain types of email encoding; =20% often appears, meaning character 0x20 which is 32 denary or the space character. It is often used where an explicit space would be illegal, and this is common in URLs and other links. I'm thinking that =25% similarly has a special meaning. It ''shouldn't'' get decoded, but software is buggy.
    I can't reproduce it here, which is why I'm asking about how and when it changes. Where does the Microsoft software come into it?

  • [svn:fx-trunk] 5313: Application, WindowedApplication, and Window background color changed to white.

    Revision: 5313
    Author: [email protected]
    Date: 2009-03-13 19:10:24 -0700 (Fri, 13 Mar 2009)
    Log Message:
    Application, WindowedApplication, and Window background color changed to white.
    QE Notes: None
    Doc Notes: None
    Bugs: sdk-16721
    Reviewer: Ryan
    tests: checkintests, cyclone build tested
    Ticket Links:
    http://bugs.adobe.com/jira/browse/sdk-16721
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/airframework/defaults.css
    flex/sdk/trunk/frameworks/projects/framework/defaults.css
    flex/sdk/trunk/frameworks/tests/checkinapp/checkinapp.css

    Hi,
    When system is in a sleep mode or hibernate mode, it will save the data ans settings in memory or hard disk, so I suggest you run a memory check and a harddisk check and see if it can detect any errors.
    Memory check (instruction is similiar to windows 8\8.1, type "memory" in the search charm bar)
    http://windows.microsoft.com/en-in/windows7/diagnosing-memory-problems-on-your-computer
    Hard disk check
    http://technet.microsoft.com/en-us/magazine/ee872425.aspx
    Meanwhile, please check event viewer to find more information, useful path: event viewer\Windows logs or event viewer\Applications and Services Logs\Kernel-power
    Yolanda Zhu
    TechNet Community Support

  • Why does JButton background color change when  clicking ?

    Hello,
    I have defined :
    JButton mybutton = new JButton(Icon xxx) ;
    with no associated text and I set both foreground and background colors to black, and an empty border.
    This is because the background color of the container which contents this button is also black and I want to see only the button icon.
    When I click on the icon , the button background color becomes grey. How can I change this to make it remains black ?
    Thanks a lot.
    Gege

    Well, the color changes because that is how the look and feel is defined,
    presumably to give better feedback to the user that she has clicked the
    button.
    If you don't want this, you could try using a different L&F which doesn't do this.
    Alternatively, If you've only got the one button, you could just do
        UIManager.put( "Button.select", Color.BLACK );If you have multiple buttons, and you want the other buttons to behave
    normally, you can extend the one button and have it change the color
    while it is pressed, e.g.,
    import java.awt.*;
    import java.io.IOException;
    import java.net.URL;
    import javax.swing.*;
    public class ButtonSelect extends JFrame {
         public ButtonSelect() throws IOException {
              super();
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel panel = new JPanel();
              panel.add( new JButton( "Normal" ) );
              Image img = Toolkit.getDefaultToolkit().getImage( new URL("http://www.google.com/intl/en/images/logo.gif" ) );
              ImageIcon ii = new ImageIcon( img );
              JButton b = new JButton( ii ) {
                   static final private String KEY = "Button.select";
                   public void paint( Graphics g ) {
                        Color save = null;
                        if ( getModel().isArmed() && getModel().isPressed() ) {
                             save = UIManager.getColor( KEY );
                             UIManager.put( KEY, Color.WHITE );
                        super.paint( g );
                        if ( save != null )
                             UIManager.put( KEY, save );
              b.setForeground( Color.WHITE );
              b.setBackground( Color.WHITE );
              b.setFocusPainted( false );
              panel.add( b );
              getContentPane().add( panel );
              pack();
              setVisible( true );
         public static void main( String[] a ) throws IOException {
              new ButtonSelect();
    }

  • How to add background color in JFrame

    I have three classes, Car, CarComponent, and CarViewer. I don't know how to code background color. Do I add it to CarViewer where the JFrame is or CarComponent?
    CarViewer:
    import javax.swing.JFrame;
    public class CarViewer
       public static void main(String[] args)
          JFrame frame = new JFrame();
          frame.setSize(300, 400);
          frame.setTitle("Two cars");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          CarComponent component = new CarComponent();
          frame.add(component);
          frame.setVisible(true);
    }CarComponent
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import javax.swing.JComponent;
       This component draws two car shapes.
    public class CarComponent extends JComponent
       public void paintComponent(Graphics g)
          Graphics2D g2 = (Graphics2D) g;
          Car car1 = new Car(0, 0);
          int x = getWidth() - 60;
          int y = getHeight() - 30;
          Car car2 = new Car(x, y);
          car1.draw(g2);
          car2.draw(g2);     
    }

    What JSG said, plus I really don't think it's a good idea to instantiate new Car objects in a paintComponent override. Painting methods should be restricted to painting activities, as a matter of principle.
    One alternative is to construct your Car instances in a separate method and call repaint() when done; another is to provide a Car method say moveTo(int x, int y) OR refactor the draw(Graphics g) method of Car to draw(Graphics g, int x, int y). Both these suggest that you maintain the Car references as instance fields of CarViewer.
    In future (not this time), Swing related questions should be posted in the [Swing forum|http://forums.sun.com/forum.jspa?forumID=57]
    db

  • Axis Legend Background Color Change?

    Is it possible to change the background color for the axis legend text? Numbers displays the chart (in this case a line chart) on the spreadsheet with the x and y legend values on a transparent background. The transparency makes the values very difficult to see, and I'm hoping there's some way to change the background or fill of the legend area to plain old white. Or even better, just change the background of the entire chart to white. Darned if I can figure out how to do such a simple thing, though.
    TIA,
    Scot

    My workaround:
    insert a rectangular rectangle whose stroke and background are white and put it behind the chart
    Yvan KOENIG (from FRANCE dimanche 12 octobre 2008 18:21:00)

  • Combo Box Background Color Change

    I have a drop down combo box with Good, Fair, Poor as the selection options. I would like to change the background color based on each slection. That is change the color to Green when Good is selected, Yellow for Fair and Red for Poor.
    Any help is geatly appreciated.

    Hi;
    This isn't something FormsCentral supports.
    Thanks,
    Josh

  • Background color change of detail pop up

    Hi,
    Please let me know the solution on how to change the detail pop up backgrond color.
    For more clarity on picture, path is, click on context menu--> details

    I am changing the lightblue  background (#F5F7F9) of the portal by downloading the theme
    and the unzip the portal.zip and then the default.properties:
    parPrtlBodyBackground=\#F5F7F9
    parDocumentBackgroundColor=\#F5F7F9
    Change the values to the required background color.
    Regards,
    Kai

  • Background color change option for box in screen painter

    have created a box in screen painter . is there any option to change the back ground color of this box.
    please help

    No, you can not change the background color of your screen painter box.

  • Background color change question - only selecting the footer

    I use the darkroom theme and was curious about changing the page background color. Right now my settings use the darkroom theme 'right out of the box' which is 'image fill' on both the page and browser background. That is the textured look.
    When I try to change the color, selecting 'color fill' instead of 'image fill', it only changes the footer - not the entire page background.
    I'm guessing it's not possible to change a color using the 'image fill.' You get 'image fill' in black or gray as shown and that is it, except should you decide to use your own image, which I do not.
    Any way to be able to have a change apply to the entire page and not just the footer?
    Suggestions welcome.

    I tried to do the same just see what the problem was and failed. It is probably 'cos the top layer is independant of the page background or browser background. Even when I had page background none and altered the browser background it made no difference. If you want anything different try using a blank black or white theme and putting your own graphics on there. You can make quite nice backgrounds if you have a decent paint or photo program.
    Message was edited by: Hazell

  • Background color change on Flex builder editor

    I have been searching around to see if there is a way to
    change the editor's backgorund. After long hours of coding, the
    white background hurt my eyes.
    I know wehre ti change the text color, and the background
    color of the console, but not the editor (source). Any idea?

    hi
    if you are using flex builder 3 you go to to:
    window->preferences
    then select General and inside it select Editors
    Inside editors you have Text Editors, select that and you
    will see what you want.

  • Background color change for  XML Template

    Hi All,
    We have created a xml template for creation of news using xml form builder. When we are creating a news by using this template the background color of the news always shows SAP default color (light blue) for both Renderlist and Show forms. Our requirement is to change the background color.
    Any help can be appreciated  and points will be rewarded immediately.
    Thanks,
    Satya

    Hi Satyadev,
    You have 3 options:
    Within the forms builder you can get a white background by setting the form to either "border" or "no border".  This is done by clicking anywhere on the form (where there is no other element) and modifying the "style" property
    You can modify the portal theme so that the background colour is your choice.  However this will affect all forms in the portal, not just this one.
    Or you can manually modify the form XSL stylesheet.  This involves typing the html code to apply your chosen colour.  However, this modification is lost if you re-generate the XML forms project, so this should be a last resort.
    Hope this helps,
    Chris

  • Background color change of a column in Advance table

    Hi,
    We have requirement to change the background color of column in advance table based on some condition. We tried putting code to change background color in Custom.xss using background-color property and setting newly created css dynamically based on condition but it seems it only changes the background color of text not the complete cell. We want to change the color of complete cell in an advance table.
    Please let me know if there is any other way I can achieve this requirement. Any help would be highly appreciated.
    Thanks

    <FONT FACE="Arial" size=2 color="2D0000">
    Pls look into "Alter Table"section.
    LOB_storage_clause
    This might help
    -SK
    </FONT>

Maybe you are looking for

  • Would like to use iWeb for a photography website

    Hi all, Please bear with me on this. The question I am going to raise has been asked on the forum in bits and pieces but don't think I was able to find a comprehensive solution to it. I currently maintain a photography website which is hosted overat

  • Install Windows 7 without optical drive

    Can someone assist please? The hard drive went in my x100e however I've received a replacement under warranty. I now need to install windows 7 onto it using supplied recovery media (DVD). I have an external optical drive however the x100e doesn't rec

  • PreparedStatement loses negative sign?!?: setInt()/setObject()

    I have 3 sql statements in my application (1 select/1 update and 1 insert) where I've noticed that after some time of working properly, all of a sudden these statements stop handling negative integers and instead process them as positive integers. i.

  • Create sequence on report

    Help please. I am trying to create sequence on the report. I wrote following PLSQL on the field emp_no in order to show sequence number (1,2,3...)on the employee_no column. It did not work. CREATE SEQUENCE Emp_sequence INCREMENT BY 1 START WITH 1 NOM

  • Including files/resources using the ADT command line

    Hi all, I'm trying to get file support into my ADT helper tool before I release an update.  I am still having problems. According to the Adobe docs on the subject, the following commands can be used: -C "path/to/new/working/directory" [files and fold