Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2008

Tip: Looking for answers? Try searching our database.

How can i change the background color of a visible JDesktopPane

Thread view: 
balla.peter@gmail.com - 12 Jan 2008 20:17 GMT
I tried this things but nothing happened ->

   getDesktopPane().setBackground(color);

   list = Tool.findComponent(getDesktopPane(), JPanel.class);

   for (int i = 0; i < list.size(); i++)
     list.get(i).setBackground(color);

   getMainFrame().getContentPane().setBackground(color);

peter

--

"No trees were destroyed in the sending of this message. However,
a large number of electrons were terribly inconvenienced."
Alexander.V.Kasatkin@gmail.com - 12 Jan 2008 21:08 GMT
On 12 янв, 23:17, balla.pe...@gmail.com wrote:
> I tried this things but nothing happened ->

Works fine (in dynamic too).

public class DesktopPaneTest {

   public static void main(String[] args) {
       final JFrame f = new JFrame("Test");
       f.setSize(400, 400);
       f.setLocationRelativeTo(null);
       f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       final JDesktopPane pane = new JDesktopPane();
       pane.setBackground(Color.RED);
       pane.addMouseListener(new MouseAdapter() {
           public void mouseClicked(MouseEvent e) {
               Color background = pane.getBackground();
               int r = 0xFF ^ background.getRed();
               int g = 0xFF ^ background.getGreen();
               int b = 0xFF ^ background.getBlue();
               pane.setBackground(new Color(r, g, b));
           }
       });

       JInternalFrame iframe = new JInternalFrame("Test");
       iframe.setBounds(10, 10, 200, 200);
       iframe.setVisible(true);
       pane.add(iframe);

       f.getContentPane().add(pane);
       f.setVisible(true);
   }
}
Knute Johnson - 12 Jan 2008 21:17 GMT
> I tried this things but nothing happened ->
>
[quoted text clipped - 10 lines]
>
> --

It works fine for me.  Are you setting the JDesktopPane as the
ContentPane of your JFrame?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test9 {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                JDesktopPane dp = new JDesktopPane();
                dp.setBackground(Color.YELLOW);
                f.setContentPane(dp);
                f.setSize(400,300);
                f.setVisible(true);
            }
        });
    }
}

Signature

Knute Johnson
email s/nospam/knute/

balla.peter@gmail.com - 12 Jan 2008 21:25 GMT
I wrote in the subject the desktop is VISIBLE. Before setVisible(true)
the color settings work fine, i use the method ->

     UIManager.put("Desktop.background", new Color(0, 100, 0));

But when the desktop is in use and i want to CHANGE the color nothing
works.

--

"No trees were destroyed in the sending of this message. However,
a large number of electrons were terribly inconvenienced."
Knute Johnson - 12 Jan 2008 21:48 GMT
> I wrote in the subject the desktop is VISIBLE. Before setVisible(true)
> the color settings work fine, i use the method ->
[quoted text clipped - 8 lines]
> "No trees were destroyed in the sending of this message. However,
> a large number of electrons were terribly inconvenienced."

Works fine for me!

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test9 {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                final JDesktopPane dp = new JDesktopPane();
                dp.setLayout(new BorderLayout());
                dp.setBackground(Color.YELLOW);
                f.setContentPane(dp);
                JButton b = new JButton("Change Color");
                b.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        dp.setBackground(Color.BLUE);
                    }
                });
                dp.add(b,BorderLayout.SOUTH);
                f.setSize(400,300);
                f.setVisible(true);
            }
        });
    }
}

Signature

Knute Johnson
email s/nospam/knute/

balla.peter@gmail.com - 12 Jan 2008 22:12 GMT
Yes this works. I use a package called

* JScroll - the scrollable desktop pane for Java.
* Copyright (C) 2003 Tom Tessier

This extends JDesktopPane and add some cool feature the best thing is -
> the desktop has a taskbar and show every JInternalFrame like windows
do.

But in the code there is nothing that deals with colors. After your
example i am sure this packega mess up something but i have no idea
what can go wrong.

--

"No trees were destroyed in the sending of this message. However,
a large number of electrons were terribly inconvenienced."
balla.peter@gmail.com - 12 Jan 2008 22:13 GMT
Yes this works. I use a package called

* JScroll - the scrollable desktop pane for Java.
* Copyright (C) 2003 Tom Tessier

This extends JDesktopPane and add some cool feature the best thing is -
> the desktop has a taskbar and show every JInternalFrame like windows
do.

But in the code there is nothing that deals with colors. After your
example i am sure this packega mess up something but i have no idea
what can go wrong.

--

"No trees were destroyed in the sending of this message. However,
a large number of electrons were terribly inconvenienced."
Knute Johnson - 12 Jan 2008 22:32 GMT
> Yes this works. I use a package called
>
[quoted text clipped - 13 lines]
> "No trees were destroyed in the sending of this message. However,
> a large number of electrons were terribly inconvenienced."

You wasted my time and Alexander's time by not giving us that little
detail up front.  I don't like that!

JScroll appears not to have been updated in years.  The website is dated
2003 and it says that the code has been tested against 1.3.1 and 1.4.1.
 1.3 is obsolete and 1.4 will be obsolete this summer.

I do my best to avoid using any third party code for exactly this reason.

Signature

Knute Johnson
email s/nospam/knute/

balla.peter@gmail.com - 12 Jan 2008 22:47 GMT
Sorry about the time waste. In these case i thougth jscroll is
transparent, it simply extends JDesktopPane. I have no clue what can
go wrong. But anyway thank you for the help.
balla.peter@gmail.com - 12 Jan 2008 22:22 GMT
Yes this works. I use a package called

* JScroll - the scrollable desktop pane for Java.
* Copyright (C) 2003 Tom Tessier

This extends JDesktopPane and add some cool feature the best thing is -
> the desktop has a taskbar and show every JInternalFrame like windows
do.

But in the code there is nothing that deals with colors. After your
example i am sure this packega mess up something but i have no idea
what can go wrong.

--

"No trees were destroyed in the sending of this message. However,
a large number of electrons were terribly inconvenienced."


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.