Solved

Background Image for JTree

Posted on 2002-04-28
5
488 Views
Last Modified: 2008-02-26
Hi,
Is it possible to add a background image for JTree?
If so, then how?
Thanks!
0
Comment
Question by:s_lavie
  • 2
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6975693
Just override the paintComponent method and paint your image. You'll also need to ensure that your cell renderers are transparent.
0
 
LVL 2

Author Comment

by:s_lavie
ID: 6990229
objects,
Can you please be more specific:
I have a file "background.gif" - I want it to be the background of a JTree.
Now step by step what do I have to do?
Thanks!
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 6992499
Override JTree and add the following method:

public void paintComponent(Graphics g)
{
   g.drawImage(image, 0, 0, this);
   super.paintComponent(g);
}
0
 
LVL 2

Author Comment

by:s_lavie
ID: 7004103
>> You'll also need to ensure that your cell
renderers are transparent.
How?
Sorry, if it's a silly question, but I've never used cell
renderers before.
Thanks again!
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7992318
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: objects
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 77
servlet filter example 37 72
Running JavaFX on JDeveloper 12C 1 54
java example issue 3 23
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question