Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can i change the background color of a visible JDesktopPane

660 views
Skip to first unread message

balla...@gmail.com

unread,
Jan 12, 2008, 3:17:32 PM1/12/08
to
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....@gmail.com

unread,
Jan 12, 2008, 4:08:04 PM1/12/08
to
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

unread,
Jan 12, 2008, 4:17:28 PM1/12/08
to
balla...@gmail.com wrote:
> 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
>
> --

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

--

Knute Johnson
email s/nospam/knute/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

balla...@gmail.com

unread,
Jan 12, 2008, 4:25:42 PM1/12/08
to
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.

Knute Johnson

unread,
Jan 12, 2008, 4:48:33 PM1/12/08
to

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

balla...@gmail.com

unread,
Jan 12, 2008, 5:12:50 PM1/12/08
to
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.

balla...@gmail.com

unread,
Jan 12, 2008, 5:13:00 PM1/12/08
to
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.

--

balla...@gmail.com

unread,
Jan 12, 2008, 5:22:15 PM1/12/08
to
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.

--

Knute Johnson

unread,
Jan 12, 2008, 5:32:18 PM1/12/08
to

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.

balla...@gmail.com

unread,
Jan 12, 2008, 5:47:00 PM1/12/08
to
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.
0 new messages