Frame Background color?

Hello
How can i change the background color of a frame? Because this wont work and i dont know what i have made wrong. So , please take a look.
Heres my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main {
private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("Game");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setDefaultLookAndFeelDecorated(true);
        //Display the window.
        frame.pack();
        frame.setBackground(Color.BLACK);
        frame.setVisible(true);
        frame.setSize(800, 576); //x 32 * 25 y= 18
        frame.setLayout(null);
        frame.setResizable(false);
public static void main(String args[]) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}Thanks
/javaguy387

write this
Container con=frame.getContentPane();
con.setBackground(Color.black);

Similar Messages

  • Data Merge: Frame background color?

    Hi everyone.
    I'm not sure if this is possible, but I'm trying to figure out a way to data merge a value to trigger the background color of a shape frame to change to another color to appear highlighted. I can already achieve this by saving out an image to match the specs of the shape I'm currently using, but for the sake of future projects and other applications I thought I would ask anyways. The document I'm merging is rather large and there will be a lot of colored shapes in the mix. Adding extra images per page will probably bump my file size a little bit - but probably not a significant amount because the shapes are pretty small.
    An example of how it looks with images:
    [merged image] [merged image shape (highlighted yellow color)] Master Text [merged text] [merged text] [merged text]
    [merged image] [merged image shape (regular grey color)] Master Text [merged text] [merged text] [merged text]
    I was thinking maybe I could use some kind of GREP style to trigger it? But I don't know if background color can be tweaked like that.
    Thanks in advance!

    GREP styles only work within paragraph styles which have character styles based on GREP queries. it can't call information about the frame it's in, only the text it is applying formatting to.
    However, I think I have a solution. draw two frames - one with a variable colour, and one with a variable picture. center them over each other and make a spreadsheet which assigns a variable pic to the variable pic frame; and a variable coloured pic to a variable colour frame.
    i've linked to an example that i've just quickly made up:
    http://colecandoo.files.wordpress.com/2011/11/bgrndchange.pdf
    to see how this was done, go to the paperclip in the bottom left of the PDF to get to the attachments.

  • Are gradients available for frame background color?

    PM 6.5.2
    Win XP Pro
    I need fancier background fills for frames. Is there a way to do gradients easier than creating the content in Photoshop then placing the resulting image into the frame?  Thanks in advance!

    InDesign replaced Pagemaker about 9 years ago.
    https://store1.adobe.com/cfusion/store/index.cfm?store=OLS-US&view=ols_prod&category=/Appl ications/InDesign&distributionMethod=UPGRADE&nr=0#store=OLS-US&view=ols_prod&category=/App lications/InDesign&loc=en_us
    Pagemaker is dead and has been for about 8 years. I like to call it Zombieware dead software that still walks the earth. The sooner you move to InDesign the better it will be for you.

  • Background Color When Adding Frames - PSE8 or PSE9

    When adding a frame to an image, the background color that is outside of the new frame, and which borders it, always comes up white for me.  Can that area be made to come up another color, and if so, how?  Thanks!

    Hi,  I understand that, but what I really want to do, and perhaps I didn't express myself clearly, is select a background color other than white and have it come up as the default color until such time as it's changed.  Thanks!
    Date: Thu, 10 Mar 2011 06:43:04 -0700
    From: [email protected]
    To: [email protected]
    Subject: Background Color When Adding Frames - PSE8 or PSE9
    For the background, you can either choose any background from the content panel or
    choose any color from the color palette
    select Paint bucket tool
    Click on a New layer icon in the layer's panel with Control/Command pressed.
    Click on the white area around the frame.
    the area is filled with the color selected.
    >

  • How to set background color for a JFrame

    Hi,
    i am new to swing programming. I have created a JFrame called framehelp and i placed some labels in the frame.
    I have set the background color as yellow for the frame ie by setBackground(new java.awt.Color(255, 255, 204));
    But after compiling the program i am still getting the background color of frame as gray.
    How can i change the background color of frame as lightish yellow.
    I have used NETBEANS to generate this code and i am posting the code..
    Kindly help me
    Thanks in adavance
    public class framehelp extends javax.swing.JFrame {
        /** Creates new form framehelp */
        public framehelp() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jLabel4 = new javax.swing.JLabel();
            jLabel5 = new javax.swing.JLabel();
            jLabel6 = new javax.swing.JLabel();
            jLabel8 = new javax.swing.JLabel();
            jLabel9 = new javax.swing.JLabel();
            jLabel10 = new javax.swing.JLabel();
            jLabel11 = new javax.swing.JLabel();
            jLabel12 = new javax.swing.JLabel();
            jLabel13 = new javax.swing.JLabel();
            jLabel7 = new javax.swing.JLabel();
            jLabel14 = new javax.swing.JLabel();
            jLabel15 = new javax.swing.JLabel();
            jLabel16 = new javax.swing.JLabel();
            jLabel17 = new javax.swing.JLabel();
            jLabel18 = new javax.swing.JLabel();
            jLabel19 = new javax.swing.JLabel();
            jLabel20 = new javax.swing.JLabel();
            jLabel21 = new javax.swing.JLabel();
            jLabel22 = new javax.swing.JLabel();
            jLabel23 = new javax.swing.JLabel();
            jLabel24 = new javax.swing.JLabel();
            jLabel25 = new javax.swing.JLabel();
            jLabel26 = new javax.swing.JLabel();
            jLabel27 = new javax.swing.JLabel();
            jLabel28 = new javax.swing.JLabel();
            jLabel29 = new javax.swing.JLabel();
            jLabel30 = new javax.swing.JLabel();
            jLabel31 = new javax.swing.JLabel();
            jLabel32 = new javax.swing.JLabel();
            jLabel33 = new javax.swing.JLabel();
            getContentPane().setLayout(null);
            setBackground(new java.awt.Color(255, 255, 204));
            setForeground(new java.awt.Color(204, 204, 204));
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            jLabel1.setText("The CAME framework software measurement process evaluation is used to determine the Level of  measurement in the ITarea. This measurementprocess evaluation is ");
            getContentPane().add(jLabel1);
            jLabel1.setBounds(40, 50, 41, 16);
            jLabel2.setText("performed individually for software coomponents ie SoftwareProduct, SoftwareProcess and SoftwareResource.");
            getContentPane().add(jLabel2);
            jLabel2.setBounds(40, 70, 41, 16);
            jLabel3.setText("Below we describe the steps which will guide through the measurement process evaluation. There are two types of evaluation considerd here, General evaluation");
            getContentPane().add(jLabel3);
            jLabel3.setBounds(40, 100, 913, 16);
            jLabel4.setText("and Evaluation with respect to a standard. The measurement intensions considerd by varoius measurement standards will be used in our tool based method.  ");
            getContentPane().add(jLabel4);
            jLabel4.setBounds(40, 120, 893, 16);
            jLabel5.setText("Information about the measurement standards can be found at     www.iso.org ,    www.ieee.org.");
            getContentPane().add(jLabel5);
            jLabel5.setBounds(40, 140, 542, 16);
            jLabel6.setText("Steps to calculate the MetricsLevel");
            getContentPane().add(jLabel6);
            jLabel6.setBounds(40, 190, 199, 16);
            jLabel8.setText("2 )  The opened frame consists of several  metrics and measures, evaluation level buttons, result textfields and selection choice lists. To calculate");
            getContentPane().add(jLabel8);
            jLabel8.setBounds(70, 240, 41, 16);
            jLabel9.setText("general Metricslevel without any standard, select general from Measurement standard choice list. then select Both from scaleType choice list and finally select metrics ");
            getContentPane().add(jLabel9);
            jLabel9.setBounds(90, 260, 949, 16);
            jLabel10.setText(" and measures from the frame and press MetricsLevel Button. The metricslevel for the selected metrics will be displayed in textfield1.");
            getContentPane().add(jLabel10);
            jLabel10.setBounds(90, 280, 756, 16);
            jLabel11.setText("3 ) To determine MetricsLevel with respect to a standard select a standard from MeasurementStandard choice list, select Both from ScaleType choice list and finally ");
            getContentPane().add(jLabel11);
            jLabel11.setBounds(70, 300, 933, 16);
            jLabel12.setText("select darkened metrics and measures and press MetricsLevel Button. The Metrics Level for the selected Metrics and standard will be diplayed in textfield1.");
            getContentPane().add(jLabel12);
            jLabel12.setBounds(90, 320, 883, 16);
            jLabel13.setText("4 ) Repeat steps 1 2, 3  for ProcessMeasurementEvaluation and ResourceMeasurementEvaluation menu items from the select menu.");
            getContentPane().add(jLabel13);
            jLabel13.setBounds(70, 340, 751, 16);
            jLabel7.setText("1 ) Select ProductMeasurementEvaluation menu item from the select menu,a frame called CAME framework software product measurement evaluation will be opened. ");
            getContentPane().add(jLabel7);
            jLabel7.setBounds(70, 220, 946, 16);
            jLabel14.setText("Steps to calculate MeasurementLevel");
            getContentPane().add(jLabel14);
            jLabel14.setBounds(50, 390, 214, 16);
            jLabel15.setText("1 ) Select ProductMeasurementEvaluation menu item from the select menu,a frame called CAME framework software product measurement evaluation will be opened.");
            getContentPane().add(jLabel15);
            jLabel15.setBounds(80, 420, 943, 16);
            jLabel16.setText("2 ) The opened frame consists of several  metrics and measures, evaluation level buttons, result textfields and selection choice lists. To calculate");
            getContentPane().add(jLabel16);
            jLabel16.setBounds(80, 450, 822, 16);
            jLabel17.setText("general Measurementlevel without any standard, select general from Measurement standard choice list. then select Quantitative measures from scaleType choice list ");
            getContentPane().add(jLabel17);
            jLabel17.setBounds(100, 470, 943, 16);
            jLabel18.setText("and finally select metrics and measures from the frame and press MeasurementLevel Button. The MeasurementLevel for the selected metrics will be displayed in textfield2.");
            getContentPane().add(jLabel18);
            jLabel18.setBounds(100, 490, 973, 20);
            jLabel19.setText("3 ) To determine MeasurementLevel with respect to a standard select a standard from MeasurementStandard choice list, select Quantitative measures from ScaleType choice list");
            getContentPane().add(jLabel19);
            jLabel19.setBounds(80, 510, 1009, 16);
            jLabel20.setText("and finally select darkened metrics and measures and press MeasurementLevel Button. The MeasurementLevel  will be diplayed in textfield2.");
            getContentPane().add(jLabel20);
            jLabel20.setBounds(100, 530, 799, 16);
            jLabel21.setText("4 )Repeat steps 1 2, 3  for ProcessMeasurementEvaluation and ResourceMeasurementEvaluation menu items from the select menu.");
            getContentPane().add(jLabel21);
            jLabel21.setBounds(80, 550, 748, 16);
            jLabel22.setText("Steps to calculate MeasurementProcessLevel");
            getContentPane().add(jLabel22);
            jLabel22.setBounds(50, 600, 262, 16);
            jLabel23.setText("1 ) Select ProductMeasurementEvaluation menu item from the select menu,a frame called CAME framework software product measurement evaluation will be opened.");
            getContentPane().add(jLabel23);
            jLabel23.setBounds(80, 630, 943, 16);
            jLabel24.setText("2 )The opened frame consists of several  metrics and measures, evaluation level buttons, result textfields and selection choice lists. To calculate");
            getContentPane().add(jLabel24);
            jLabel24.setBounds(80, 650, 819, 16);
            jLabel25.setText("general MeasurementProcesslevel without any standard, select general from Measurement standard choice list. then select Quantitative measures from scaleType ");
            getContentPane().add(jLabel25);
            jLabel25.setBounds(100, 670, 930, 16);
            jLabel26.setText("choice list, enter migrated metrics if any in textfield  below migrated metrics label and finally select metrics measures from the frame and press ");
            getContentPane().add(jLabel26);
            jLabel26.setBounds(100, 690, 818, 16);
            jLabel27.setText("MeasurementProcessLevel Button. The MeasurementProcessLevel for the selected metrics will be displayed in textfield3.");
            getContentPane().add(jLabel27);
            jLabel27.setBounds(100, 710, 691, 16);
            jLabel28.setText("3 ) To determine MeasurementProcessLevel with respect to a standard select a standard from MeasurementStandard choice list, select Quantitative measures from ");
            getContentPane().add(jLabel28);
            jLabel28.setBounds(80, 740, 937, 16);
            jLabel29.setText("from ScaleType choice list, enter migrated metrics if any in textfield below migrated metrics and finally select darkened metrics and measures and press  ");
            getContentPane().add(jLabel29);
            jLabel29.setBounds(100, 760, 873, 16);
            jLabel30.setText("MeasurementProcessLevel Button. The MeasurementprocessLevel for the selected metrics will be displayed in textfield3");
            getContentPane().add(jLabel30);
            jLabel30.setBounds(100, 780, 687, 16);
            jLabel31.setText("4 ) Repeat steps 1,2,3 for ProcessMeasurementEvaluation and ResourceMeasurementEvaluation menuitems.");
            getContentPane().add(jLabel31);
            jLabel31.setBounds(80, 800, 618, 16);
            jLabel32.setText("Steps to calculate MeasuredSoftwareProcessLevl");
            getContentPane().add(jLabel32);
            jLabel32.setBounds(60, 830, 285, 16);
            jLabel33.setText("1 ) Follow the same steps as MetricsLevel calcualtion but select metrics and measures covered by CAME Tools only.");
            getContentPane().add(jLabel33);
            jLabel33.setBounds(90, 860, 657, 16);
            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-1100)/2, (screenSize.height-940)/2, 1100, 940);
        /** Exit the Application */
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
         * @param args the command line arguments
        public static void main(String args[]) {
            new framehelp().show();
        // Variables declaration - do not modify
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel10;
        private javax.swing.JLabel jLabel11;
        private javax.swing.JLabel jLabel12;
        private javax.swing.JLabel jLabel13;
        private javax.swing.JLabel jLabel14;
        private javax.swing.JLabel jLabel15;
        private javax.swing.JLabel jLabel16;
        private javax.swing.JLabel jLabel17;
        private javax.swing.JLabel jLabel18;
        private javax.swing.JLabel jLabel19;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel20;
        private javax.swing.JLabel jLabel21;
        private javax.swing.JLabel jLabel22;
        private javax.swing.JLabel jLabel23;
        private javax.swing.JLabel jLabel24;
        private javax.swing.JLabel jLabel25;
        private javax.swing.JLabel jLabel26;
        private javax.swing.JLabel jLabel27;
        private javax.swing.JLabel jLabel28;
        private javax.swing.JLabel jLabel29;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel30;
        private javax.swing.JLabel jLabel31;
        private javax.swing.JLabel jLabel32;
        private javax.swing.JLabel jLabel33;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JLabel jLabel6;
        private javax.swing.JLabel jLabel7;
        private javax.swing.JLabel jLabel8;
        private javax.swing.JLabel jLabel9;
        // End of variables declaration
    }

    1. When you post code, post a minimal example. Did we have to scroll through
    all those bloody labels.
    2. Can't say much for the quality of code NetBeans generates.
    3. To answer your question (sorry, I don't have an autographed copy of the photo):
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    public class Example {
        public static void main(String[] args) throws MalformedURLException {
            final JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Container cp = f.getContentPane();
            cp.setBackground(new Color(0xff, 0xff, 0xee));
            cp.add(new JLabel("set the color on the content pane, not the frame"), BorderLayout.SOUTH);
            URL url = new URL("http://today.java.net/jag/bio/JagHeadshot-small.jpg");
            cp.add(new JLabel(new ImageIcon(url)));
            f.pack();
            SwingUtilities.invokeLater(new Runnable(){
                public void run() {
                    f.setLocationRelativeTo(null);
                    f.setVisible(true);
    }

  • How can I create an alt background color for items in a jlistbox or jtree

    What I'm looking to do is have a white background for say items 1,3,5, etc. and a light yellow background for items 2,4,6, etc. I was wondering how can I set an alternative background color on items in a JTree or a JList

    Use a cell renderer:
    import java.awt.*;
    import javax.swing.*;
    public class ListAlternating extends JFrame
         public ListAlternating()
              String[] items = {"one", "two", "three", "four", "five", "six", "seven"};
              JList list = new JList( items );
              list.setVisibleRowCount(5);
              list.setCellRenderer( new MyCellRenderer() );
              JScrollPane scrollPane = new JScrollPane( list );
              getContentPane().add( scrollPane );
         public static void main(String[] args)
              ListAlternating frame = new ListAlternating();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );
         class MyCellRenderer extends DefaultListCellRenderer
              public Component getListCellRendererComponent(
                   JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
                   super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                   if (!isSelected)
                        setBackground(index % 2 == 0 ? list.getBackground() : Color.LIGHT_GRAY);
                   return this;
    }

  • How to change the background color of a sequence?

    I'm using Premiere Pro CS5 on Win7 x64.  I've imported a JPEG that's a different size than my 1920 x 1080 frame.  The background of this JPEG is white, but the background of the sequence is black (by default), so the borders of the JPEG make it stand out.  I want the JPEG to blend into the sequence background by making the sequence background white.  How can I change the sequence background color?  Thanks.

    Jim and Ann are correct. I can see where someone used to After Effects might ask that question though because in AE you can change the background color of the composition. Same with Photoshop.
    However, I think it would confuse things if changing the background color were to be allowed in Premiere Pro. Black tells me something. I suppose white could tell me the same thing, but at this time it is not possible in Premiere Pro.

  • Change the background color of a title bar

    I'd like to know if it's possible to change the background color of a swing application title bar.
    Thanks in advance.

    In Windows I think you can change the overall look of the desktop - Standard Windows comes with a bluish scheme, but you can change that, say to something like greenish. On NT you do it using right click on desktop > Properties > Apperance > Scheme etc etc.
    So I think Frame title colour is very much a OS specified thing.

  • How to change background color in a window? Please help.

    Please help me to set background color to my window that includes some panels components.
    I have tried
    content.setBackground(Color.green); and
    frame.setBackground(Color.RED);
    but nothing works?
    Please what should I change in my code? Thanks already in advance for helping!!
    Main parts of my code:
    public void addComponentToPane(Container allComponents) throws IOException
    definePanels();
    allComponents.setLayout(new BoxLayout(allComponents, BoxLayout.Y_AXIS));
    allComponents.add(panel_introduction);
    allComponents.add(panel_n);
    allComponents.add(panel_resultTitle);
    allComponents.add(panel_w);
    allComponents.add(panel_testing);
    allComponents.setVisible(true);
    public static void main(String[] args) throws IOException
    try {
    GraphicsDevice device;
    Container content;
    JFrame frame = new JFrame("ImageOrder");
    device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    device.setFullScreenWindow(frame);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SwingApplication app = new SwingApplication();
    content = frame.getContentPane();
    content.setBackground(Color.green);
    app.addComponentToPane(content);
    frame.setVisible(true);
    finally {
    System.out.println("helle");
    }

    import java.awt.Color;
    import javax.swing.*;
    class Test extends JFrame {
         public Test( ){
              getContentPane().setBackground(Color.RED);
              pack();
              setSize(500, 500);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String[] argv) {
              new Test().setVisible(true);
    }

  • 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

  • Browser Background Color Not Drawing Completely

    On the web page I recently uploaded, the page does not draw the browser background color completely when it loads. The browser background color fills in to the bottom of the sized page, below there it is white.
    1. Modern Frame 2.0 - Blank
    2. Set Browser Background color to Blue
    3. Page background color either the same Blue or none at all. I've tested both ways.
    4. Manual resize always allows the browser background color to fill in properly.
    5. Footer on and off. Doesn't make a difference.
    After uploading to the web, clearing all my caches, it continues to fill in incompletely.
    What do you suggest I do to solve this?
    Thank you - Fabe

    Give us the URL for the site so we can examine it first hand. With out looking at the site you should change the theme to White theme which does not use files for background and therefore will not restrict the amount of space the background takes up. That's just a guess though.
    OT
    Message was edited by: Old Toad

  • 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);
    }

  • How do I apply a specific background color in InDesign?

    The background color is identified in Ps as "edf7e4", and it is a very pale green.  How do I make this the background color for my book cover in InDesign?

    You must add a frame to your cover page(s) at the bottom of the stack and fill it with the color that you wish to use (you can keep the RGB definiton and convert on export, too, if you need CMYK for press). Don't forget to bleed the edges where required.

  • How to use a GradientPaint as background color in a JPopupMenu

    I want to use a GradientPaint as background color in a JPopupMenu.
    I try to use something like
    GradientPaint p;
    p = new GradientPaint(0, 12, Color.white, 0, 24, Color.pink);
    UIManager.put("MenuItem.selectionBackground", p);but it doesn't work.
    I also tried to extends BasicMenuItemUI in MenuItems
    public class CMenuItem extends JMenuItem {
         public CMenuItem(String text) {
              super(text);
              setUI(BUI.createUI(this));
         static final class BUI extends BasicMenuItemUI {
             private final static BUI ui = new BUI();
             public static BUI createUI(JComponent c) {
                 return ui;
             @Override
             public void update(Graphics g, JComponent c) {
                   if (c.isOpaque()) {
                        Graphics2D g2 = (Graphics2D)g.create();
                        int w = c.getWidth();
                        int h = c.getHeight();
                        GradientPaint p;
                        p = new GradientPaint(0, 12, Color.white, 0, 24, Color.pink);
                        g2.setPaint(p);
                        g2.fillRect(0, 0, w, h);
                        g2.dispose();
                   paint(g, c);
    }I used this technique for JLabel and it works fine.
    Please help

    ok, here the SSCCE. I hope its helpful for an answer.
    import java.awt.Color;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.UIManager;
    import javax.swing.plaf.basic.BasicMenuItemUI;
    public class Menu {
        public JMenuBar createMenuBar() {
             JMenuBar menuBar;
            JMenu menu;
            JMenuItem menuItem;
            //Create the menu bar.
            menuBar = new JMenuBar();
            //Build the first menu.
            menu = new JMenu("A Menu");
            menuBar.add(menu);
             GradientPaint p;
             p = new GradientPaint(0, 12, Color.white, 0, 24, Color.pink);
             UIManager.put("MenuItem.selectionBackground", p);
            menuItem = new JMenuItem("1st item: when selected its background is black: wrong");
            menu.add(menuItem);
             UIManager.put("MenuItem.selectionBackground", Color.pink);
            menuItem = new JMenuItem("2nd item: when selected its background is pink: ok");
            menu.add(menuItem);
            menuItem = new CMenuItem("3rd item: when selected its background is pink: WRONG!");
            menu.add(menuItem);
            return menuBar;
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            Menu demo = new Menu();
            frame.setJMenuBar(demo.createMenuBar());
            //Display the window.
            frame.setSize(450, 260);
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    class CMenuItem extends JMenuItem {
         private static final long serialVersionUID = 1L;
         public CMenuItem(String text) {
              super(text);
              setUI(BUI.createUI(this));
         static final class BUI extends BasicMenuItemUI {
             private final static BUI ui = new BUI();
             public static BUI createUI(JComponent c) {
                 return ui;
             @Override
             public void update(Graphics g, JComponent c) {
                   if (true || c.isOpaque()) {
    //                    System.out.println("update()");
                        Graphics2D g2 = (Graphics2D)g.create();
                        int w = c.getWidth();
                        int h = c.getHeight();
                        GradientPaint p;
                        p = new GradientPaint(0, 0, Color.white, 0, 10, Color.pink);
                        g2.setPaint(p);
                        g2.fillRect(0, 0, w, h);
                        g2.dispose();
                   paint(g, c);
    }Thanks for the help

  • JFrame background color

    I have a JFrame and I'm setting the background color in the constructor:
    frame.setBackground(Color.green);
    The frame opens up, and the background color flashes green for an instant, then it goes back to grey. What am I missing? Do I have to set the background color in the paint() method?
    TIA,
    Rich

    I found a post from back in April about setting the background color of the contentPane instead, and that works.
    Thanks anyway!
    Rich

Maybe you are looking for

  • Beginner iOS developer...questions on the universal UI

    I'm a first time iOS developer and working on completing a universal puzzle app that supports iOS 6 and above. On the UI front the main UI has 4 buttons (using a custom UI round button class from cocoacontrols.com) and a About button (at the bottom)

  • Backing up Air SSD and external drive to Time Machine

    Hi Sincere apologies if this has been asked and answered but I cannot find an answer or phrase a search properly to do so.  I have a 500gb MacBook and am planning to get a MacBook Air.  I would like to move much of the content from my MacBook to an e

  • Error while reading excel file from application server into internal table.

    Hi experts, My requirement is to read an excel file from application server into internal table. Hence I have created an excel file fm_test_excel.xls in desktop and uploaded to app server using CG3Z tcode (as BIN file type). Now in my program I have

  • Swipe gesture not working in safari

    After upgrading to Mavericks the swipe gesture (previous page) in safari is not working and if I swipe ( i am so used to it now), it causes the safari to freeze. Anybody else have same problem

  • # of commits using BAPI_TRANSACTION_COMMIT in integration?

    Hi all, my question is how many times can use BAPI_TRANSACTION_COMMIT BAPI for commiting data in SAP Standard tables? curently I am calling BAPI_TRANSACTION_COMMIT for every BP created in CRM. Ours is integration from legacy to CRM, and this job runs