Java Swing Change background with button

change the backgroung by press ing a swing buton and windowhandlers
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class backgrframe extends JFrame{
     class windowHandler extends WindowAdapter {
          public void windowClosing(WindowEvent e){
               System.exit(0);
     class buttonHandler implements ActionListener {
          public void actionPerformed(ActionEvent e){
          String s = e.getActionCommand();
          System.out.println("S : " +s );
               if( s.equals("Red") )
                    getContentPane().setBackground(Color.red);
               else if( s.equals("Green") )
                    getContentPane().setBackground(Color.green);
               else if( s.equals("Blue") )
                    getContentPane().setBackground(Color.blue);
          backgrframe(){
               super("Background Frame");
               setSize(400,300);
               getContentPane().setBackground(Color.red);
               getContentPane().setLayout( new FlowLayout() );
               JButton red = new JButton ("Red");
               JButton green = new JButton ("Green");
               JButton blue = new JButton ("Blue");
               buttonHandler bh = new buttonHandler ();
               red.addActionListener(bh);
               green.addActionListener(bh);
               blue.addActionListener(bh);
               windowHandler wh = new windowHandler ();
               addWindowListener(wh);
               getContentPane().add(red);
               getContentPane().add(green);
               getContentPane().add(blue);
               setVisible(true);
     public static void main(String args[]){
               new backgrframe();

I could be wrong here but don't you have to set the actioncommand for each button?
eg red.setActionCommand("Red") etc

Similar Messages

  • Can Photoshop make a background with buttons for iDVD?

    Can I create a background in Photoshop (v. 7) and include buttons which work in iDVD6?
    I think so, from reading here and there, and that each button must be on a separare layer. Correct?
    Is there a tutorial or similar on how to do this?
    Thanks.

    SteveKir
    you may be able to purchase an apple original CD of
    DVD SP (used) like I did on ebay for pennies on the
    dollar. Works great for backgrounds and button
    creation! Doesn't have to be the latest version for
    it to work well. Good luck.
    SDMacuser
    I have never used ebay and am not comfortable letting them store my credit card details long-term (risk of hacking etc.) However, I am comfortable using the internet a lot for purchases from individual well-known companies I trust (including Amazon, most of which do not store my credit card details), compared to unknowns on ebay. Three questions please:
    1. What are people's experience of buying from "unknown" sellers on ebay? and
    2. A 1.1 version of DVD Studio Pro is available on ebay. Would that (very old) version allow me to use Photoshop to create DVD backgrounds with buttons designed within Photoshop as part of the Photoshop file? and
    3. Do you think that such an old version would work with QT 7? (Often Apple products do not like working with such "time-zone" differences.)
    Thanks for any help.
    G5/2.0 GHz Mac OS X (10.3.9) 1 GB RAM, 150 GB HD, Sony DCR-HC96 mini DV, FCE HD 3.0

  • Can I change background with Lightroom?

    Can I change background with lightroom?? Please help me. Thank u

    Hi behzad,
    to requote my message #2: Right-click the right window scrollbar (VI in edit mode) and select "properties"…
    What don't you understand of this?
    When you don't trust me you should read the LabVIEW help on this topic!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Changing JPanel with button click.

    Hi, I have a class call TOC(Table of Content) which contains all the buttons. One class call MainController. All buttons I add an actionListener which the MainController class will handle. Anothe class which is the main one which contain a JPanel.
    When I click on the button in TOC class, it will go through the MainController class and display the respective JPanel associate with the button.
    Now the problem is how do I change the JPanel in the main class with a click on the button in TOC class?
    Please advise. Thanks in advance.

    Not sure what you mean exactly. However,
    Assuming that your view class is a JPanel, when you create your controller,
    ViewPanel view = new ViewPanel();
    MainController controller = new MainController(viewPanel);
    In MainController track a reference to your viewPanel. Also in viewPanel have a method called setCurrentPanel(JPanel panel). then int he controller's action listener
    public void actionPerformed(ActionEvent ev) {
    JPanel pnl = (JPanel) panelMap.get(ev.getSource().getName());
    viewPanel.setCurrentPanel(pnl);
    I am assuming you have a way of mapping each button to the panel it will use, which is what is in the panelMap. The viewPanel can have a CardPanel layout for the panels it displays and its setCurrentPanel, can bring to front/oradd the specified panel.
    Good luck, hope this helps :-)

  • Change background with rollover?

    Not sure if it can be done (maybe a different way than I'm trying to figure out), but my goal is to have an image that fills the entire window, even if it's resized.  Then, when you rollover a menu option, the image will change to a different photo.  I'm very new to Muse and the only way I have found to make the photo change with the size of the browser is to fill the browser with an image.  However, I can't find a way to make the image change without having a completely different master page and actually clicking a link to that page.  I want my end result to be something like this:   http://gavingough.photoshelter.com/#!/index 
    Thanks in advance!

    Hello,
    Check this post on how to create a full screen slideshow, with examples etc: http://forums.adobe.com/thread/1213057
    With that in place, you can also place link on the triggers, pointing to the pages they would open when clicked upon.
    Hope this helps.
    Cheers
    Parikshit

  • Change tabs with buttons

    Hi Everyone
    I have 5 tabs:
    tab1 = user tab (which will contain 4 buttons: button 1, button2, button3, button4)
    When button 1 is pressed tab 2 screen is user interface
    When button 2 is pressed tab 3 screen is user interface
    When button 3 is pressed tab 4 screen is user interface
    When button 4 is pressed tab 5 screen is user interface
    I tried to do this using Boolean buttons so when the button is pressed it will change to the correct page is there a better way to do this?
    Ailish

    I use this method quite a bit, within a state machine, attached is a basic example..
    Cheers
    Attachments:
    StandardStateMachine_UserTabs.zip ‏13 KB

  • How to change background in bulk

    Hi All,
    I have made simulation type project in English version using Captivate 4. Now, I want to develop this project in multilingual. I can change the caption text easily using the export command. But I want to change the background for multilingual.
    Do you have any idea about it.
    Regards,
    Manshu

    If you have a lot of slides that share the same single background, you can change that background on multiple slides at once by:
    In Edit view, with the Filmstrip pane visible, hold down the CTRL key and click on each slide in the Filmstrip pane you want to change.
    Right-click one of the selected slides and choose Properties.
    On the Properties dialog, click the Change Background Image button and select the desired background.
    Result:  The background you choose will be applied to each of the slides selected in the Filmstrip pane.
    A better approach is to build your original project by importing external images into your project and then using the Update feature in the Captivate library to replace all your images with "localized language" versions.
    The advantage of using imported images is that Captivate "remembers" the folder location of each image and you can easily tell Captivate to reimport those images at any time:
    Capture all your images using dedicated screen capture software (the Snipping tool included in Windows 7 will work).  Save each image to a folder on your hard drive (or folders, if you want to be super organized) using meaningful file names to allow you to easily identify and update each image later.
    Build your initial Captivate project by importing each image from your hard drive.
    Make a backup copy of the original images on your hard drive.
    Overwrite the original images on your hard drive with "localized language" versions, using the exact same file names.
    In Captivate, select all the images in your Library that you want to update.
    Right-click one of the selected images and choose Update.
    Click the Update button.
    Save the updated project with a new file name that reflects the new language.
    Result:  Captivate replaces all the selected images with the updated versions from your hard drive.
    If you haven't already been using imported images in your project, you can start by importing an initial set of localized images and then use the Overwrite and Update trick for each successive language.
    In a pinch, you can also capture all your images using Captivate, but this requires you to first export the images from the Captivate Library to a folder, then reimport them one at a time from the hard drive to establish the "folder path" that Captivate needs for the Update feature to work.
    Cheers,
    John

  • Problem with java swing button and loop

    Problem with java swing button and loop
    I�m using VAJ 4.0. and I�m doing normal GUI application. I have next problem.
    I have in the same class two jswing buttons named start (ivjGStart) and stop (ivjGStop) and private static int field named Status where initial value is 0. This buttons should work something like this:
    When I click on start button it must do next:
    Start button must set disenabled and Stop button must set enabled and selected. Field status is set to 1, because this is a condition in next procedure in some loop. And then procedure named IzvajajNeprekinjeno() is invoked.
    And when I click on stop button it must do next:
    Start button must set enabled and selected and Stop button must set disenabled.
    Field status is set to 0.
    This works everything fine without loop �do .. while� inside the procedure IzvajajNeprekinjeno(). But when used this loop the start button all the time stay (like) pressed. And this means that a can�t stop my loop.
    There is java code, so you can get better picture:
    /** start button */
    public void gStart_ActionEvents() {
    try {
    ivjGStart.setEnabled(false);
    ivjGStop.setEnabled(true);
    ivjGStop.setSelected(true);
    getJTextPane1().setText("Program is running ...");
    Status = 1;
    } catch (Exception e) {}
    /** stop button */
    public void gStop_ActionEvents() {
    try {
    ivjGStart.setEnabled(true);
    ivjGStart.setSelected(true);
    ivjGStop.setEnabled(false);
    getJTextPane1().setText("Program is NOT running ...");
    Status = 0;
    } catch (Exception e) {
    /** procedure IzvajajNeprekinjeno() */
    public void IzvajajNeprekinjeno() {  //RunLoop
    try {
    int zamik = 2000; //delay
    do {
    Thread.sleep(zamik);
    PreberiDat(); //procedure
    } while (Status == 1);
    } catch (Exception e) {
    So, I'm asking what I have to do, that start button will not all the time stay pressed? Or some other aspect of solving this problem.
    Any help will be appreciated.
    Best regards,
    Tomi

    This is a multi thread problem. When you start the gui, it is running in one thread. Lets call that GUI_Thread so we know what we are talking about.
    Since java is task-based this will happen if you do like this:
    1. Button "Start" is pressed. Thread running: GUI_Thread
    2. Event gStart_ActionEvents() called. Thread running: GUI_Thread
    3. Method IzvajajNeprekinjeno() called. Thread running: GUI_Thread
    4. Sleep in method IzvajajNeprekinjeno() on thread GUI_Thread
    5. Call PreberiDat(). Thread running: GUI_Thread
    6. Check status. If == 1, go tho 4. Thread running: GUI_Thread.
    Since the method IzvajajNeprekinjeno() (what does that mean?) and the GUI is running in the same thread and the event that the Start button has thrown isn't done yet, the program will go on in the IzvajajNeprekinjeno() method forever and never let you press the Stop-button.
    What you have to do is do put either the GUI in a thread of its own or start a new thread that will do the task of the IzvajajNeprekinjeno() method.
    http://java.sun.com/docs/books/tutorial/uiswing/index.html
    This tutorial explains how to build a multi threaded gui.
    /Lime

  • Transparent Buttons in Java Swing?

    Hi!
    I want to create transparent Buttons using java swing for my desktop application. Can any one tell me how to do it?

    I can help, but it depends on what you mean by "transparent".
    Do you mean TOTALLY transparent, or slightly transparent, or merely translucent? Do you want the text on the button to be in any way transparent? You really need to be more specific.
    Basically, though, the concept is pretty simple. All swing components have several methods that can be overridden by somebody who knows what they are doing, in order to customize their appearances.
    Some of these are: paint(), paintComponent(), ComponentUI.paint(), etc.
    You need to determine the right place to put the new code. Then you extend the class, and change the transparency of the graphics object passed into the method in question, and then pass control to the super implementation of that method.
    There are some traps you need to make sure you avoid, though:
    1. If you want transparent components, you MUST have the opaque property of the component set to false. Otherwise, the components beneath your transparent button will never update.
    2. When you start messing with a graphics object to create transparency, you need to make sure that you revert your changes to the graphics object when you are finished, because all painting uses the same graphics object -> so if you set your button transparent, and then forget to remove the transparency, all objects drawn after the button will also be drawn transparent.
    A word of caution:
    This sort of manipulation is not hard, but you NEED to understand the painting model for SWING. There are a few articles hosted by sun that can help you in this respect.
    Good Luck!
    - Adam

  • [SOLVED] XFCE - Java Swing button theme?

    I'm running XFCE, and I notice that all Swing-based Java applications use the ugly Swing button theme. When I used GNOME 3, some of them would adapt to the GNOME button theme (and would look like they belonged on the system).
    Is this issue with XFCE, my current GTK theme (dorian), or Java, and how can I change this?
    Last edited by 2mac (2014-01-01 22:17:07)

    Thank you for the information.
    I followed the wiki by adding
    export _JAVA_OPTIONS="-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
    to my ~/.bashrc file.
    To test, I launched the Minecraft launcher (one of the applications which does support style changes between desktops), and got back this information:
    Picked up _JAVA_OPTIONS: -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel
    Error parsing gtk-icon-sizes string: ''
    And it had no effect. Any ideas?
    Last edited by 2mac (2013-12-31 16:35:39)

  • Unicode characters with accents won't display in Java Swing applications

    I'm using FreeMind (a Java Swing application) and I need to enter classical Greek characters with accent marks. When I type an accented Greek character, FreeMind displays the unaccented character. However, I can type the accented character in MS Word, then copy and paste into FreeMind, the accented character appears.
    One of the FreeMind developers indicated this was a Java Swing issue, not FreeMind, and suggested I test with another Swing application. So, I installed jEdit and got exactly the same results. I can paste an accented character into jEdit, but I cannot type it in directly.
    I'm using Windows Vista with Java 6 Update 22 (build 1.6.0_22-b04). I also tested on a XP Pro box with Java 1.6.0_18-b07 and got the same result.
    One other note: A couple days ago, I was able to type accented Greek characters into FreeMind. But it only worked for a couple days and then the behavior reverted to unaccented characters. It is possible, but I don't recall specifically, that I updated Java during the time and that may indicate a bug in one version of Java but not another.
    Any assistance or guidance would be greatly appreciated!
    Darin

    Walter,
    The link you provided does not appear to describe the Greek Polytonic keyboard. (The page also describes using the "Option" key as the dead key. There is no "Option" key on my keyboard. I'm using a Sony VGN-NS140E purchased in Chicago, i.e. standard physical US keyboard.)
    Please see http://darindavis.net/languages/keyboard_Greek.pdf for a detailed description of how to use the Greek (Polytonic) keyboard in Windows to produce a complete set of accented classical Greek characters. This method works in MS Word and Notepad. I enabled the Greek (Polytonic) keyboard with:
    Windows (Vista) Start > Control Panel > Regional and Language Options > Change Keyboards > General > Add > Greek (Greece) > Greek Polytonic
    A test that will demonstrate whether you can replicate the error is to do the following in both MS Word (or Notepad) and jEdit (or FreeMind):
    1. Enable the Greek Polytonic keyboard
    2. Type "\" then "e" which should produce an epsilon with smooth breathing and grave accent (ἒ)
    When I do this in MS Word or Notepad, I see the epsilon with smooth breathing and grave accent. When I do this in jEdit and FreeMind, I only see an epsilon.
    I recorded a screencast to illustrate the problem: http://www.screencast.com/t/TRKkKQrCgbN
    Actually, this problem is transient. Sometimes FreeMind or jEdit will display accented characters, other times it won't. Ironically, the first time I recorded the above referenced screencast, a few characters in jEdit did appear with accents. A couple minutes later, I re-recorded the screencast and as you can see jEdit did not display the accents. Between the two recordings I literally did nothing other than stop the Jing recording and start a new one. There is another variable at play here and I can't determine what it is. The most likely source seems to be Java since MS Word and Notepad consistently display accent characters.
    Thanks,
    Darin

  • Draggable buttons in Java Swing

    Hi,
    I want to develop an application in Java Swing. The application I am going to develop is an application for developing other applications. I want my application to include a button which also acts as a drag and drop UI element. For example, I want my application to include a button for adding a picture. There are 4 buttons of different pictures. If a user wants to add a picture he can either click on one of these buttons and that picture will be added somewhere on the screen or dragging this button and drop it and that picture will be added where he dropped that button.
    Could anyone please tell me…
    1. If I can develop an application which includes Drag and Drop UI element if I develop it in Java Swing
    2. If a button (or other UI element) can act as both a button and a drag and drop element if I develop my application in Java Swing
    3.
    Could you please tell me where I can find some screenshots of applications which has been developed in Java Swing? I am not familiar with this program and I am not that good at programming, so I would like to get some impression of how it might look like.
    Thanks in advanced

    1. the good thing about Swing is that it is very flexible and with clever programming you can do just about anything. The problem is that depending on your requirements, this could require a great deal of programming that can be very hard to implement such that it works properly on all popular platforms (windows, linux, mac).
    2. see 1.
    3. Swing applications are "skinnable", you can give them a great number of different appearances. The default is to give the application a system look and feel, so they look pretty much like any other application for that platform. This means that when you run your application on Windows, it will look like a Windows application, if you run it on a Mac it will look like a Mac application, etc.
    I am not familiar with this program and I am not that good at programmingThat is quite a problem, because Swing is not the easiest API around. It requires a solid knowledge of Java and Object Oriented Programming in general as the entire API is based heavily on OOP concepts. To get a better idea of Swing, read through the Swing tutorial here:
    http://java.sun.com/docs/books/tutorial/uiswing/

  • How do I add "change background/foreground color" to the configurator, and color buttons?

    How do I add "change background color" and "change foreground color" in the configurator?
    Also is there a way to color buttons?
    Regards,
    Glen

    No matter whether you mean the application Configurator or a Panel created with Configurator you would probably do well to post the question on the Configurator Forum.
    Configurator

  • Java Swing frame for modification Excel file or Word file with All menu...

    Hello All,
    Can Any one help me for making java Swing frame for modification Excel Data or word file with all Menu.. Plz send me java Code for that.. I am bit new in Swing.
    i am waiting for ur help..
    Thanks
    Samir

    hi pbrockway2 ,
    Can you go through this program Sir, i am trying to call Excel content below of menu. when i will press Edit button then excel content should come below with Cut, copy, paste , Save Button..
    Plz help me sir...
    import javax.swing.*;
    import java.io.*;
    import java.awt.event.*;
    public class TestReader
    private static void createAndShowUI()
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame=new JFrame("Test Reader");
    JButton button=new JButton("Edit");
    button.addActionListener(new ButtonListener());
    frame.getContentPane().add(button);
    frame.setVisible(true);
    frame.pack();
    static class ButtonListener implements ActionListener
    public void actionPerformed(ActionEvent event)
    openTheFile();
    private static void openTheFile()
    try
    String commands[]=new String[3];
    commands[0]="cmd.exe";
    commands[1]="/C";
    commands[2]="INSTALL.LOG"; // here file name is supposed to be in the working dir
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec(commands);
    StreamGobbler errorGobbler=new StreamGobbler(proc.getErrorStream(),"ERROR");
    StreamGobbler outputGobbler=new StreamGobbler(proc.getInputStream(),"OUTPUT");
    errorGobbler.start();
    outputGobbler.start();
    catch (Exception e){}
    public static void main(String args[])
    SwingUtilities.invokeLater(new Runnable()
         public void run()
         createAndShowUI();
    static class StreamGobbler extends Thread
    InputStream is;
    String type,root;
    StreamGobbler(InputStream is,String type)
    this.is=is;
    this.type=type;
    public void run()
    try
    InputStreamReader isr=new InputStreamReader(is);
         BufferedReader breader=new BufferedReader(isr);
         String line=null;
         while ((line=breader.readLine())!=null)
         System.out.println(type+">"+line);
    catch (Exception e)
         System.out.println(e);
    Thanks
    SamiR

  • How to realize them with Java Swing?

    1.I want to realize the function - Save, which is similar with "save" in windows notepad - after clicking "save", a dialog box is poped up, then i can input the filename and save it. Is there any ready class like JFileChooser in Java Swing?
    2.I want to set Font and color in the text area. I can do it now. But I must set the font and color b4 input the words. How can I do it like Windows Word - I just input my words, then I highlight them and select the font and colour....all highlighted words r change....can I don it with Java swing and how?
    Thanks..

    1.I want to realize the function - Save, which is
    similar with "save" in windows notepad - after
    clicking "save", a dialog box is poped up, then i can
    input the filename and save it. Is there any ready
    class like JFileChooser in Java Swing?JFileChooser is a Swing based dialog, use it for your problem.
    >
    2.I want to set Font and color in the text area. I can
    do it now. But I must set the font and color b4 input
    the words. How can I do it like Windows Word - I just
    input my words, then I highlight them and select the
    font and colour....all highlighted words r
    change....can I don it with Java swing and how?
    Thanks..I am currently working this, try the ElementIterator w/ the Document that your inputing, as you iterate throught the nodes, you modify the attribute sets there.
    Hope this helps.
    >

Maybe you are looking for