The Artima Developer Community
Sponsored Link

Java Answers Forum
Setting Image as Background for JFrame.

9 replies on 1 page. Most recent reply: Jun 17, 2005 5:35 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 9 replies on 1 page
Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Setting Image as Background for JFrame. Posted: Jun 13, 2005 8:31 AM
Reply to this message Reply
Advertisement
Hi folks:

I have a JFrame, in it there is a JTable table1;

Please give me some suggestions on how to set a
background image for the table.

I have googled this like crazy but to no avail.

Thanks in advance.

Spike


barron

Posts: 13
Nickname: toniblair
Registered: May, 2005

Re: Setting Image as Background for JFrame. Posted: Jun 13, 2005 10:02 AM
Reply to this message Reply
here's an idea...
If you can use a JList instead of a JTable (JLists are non-editable -- for display only) You can pass in an array of JLabels as the list data. Now to get an image as the background for the JList, you simply override the paint(Graphics g) function of each JLabel. Using this method you could either use the same image in each Label, or write some function to draw only the correct piece of the whole background image in each of the labels. Kind of like a mosaic. There may be a simpler solution, but this should work...

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Setting Image as Background for JFrame. Posted: Jun 13, 2005 11:53 PM
Reply to this message Reply
Thanks man... I'll try it out...

Don't you think it would be great though if Sun
introduced a method signed:

void setBackgroundImage(Image im)

for Components in the next Java release?

Jack

Posts: 10
Nickname: zyppora
Registered: Jan, 2005

Re: Setting Image as Background for JFrame. Posted: Jun 14, 2005 2:37 AM
Reply to this message Reply
You have to keep in mind that even though Swing is great for building GUIs, Java is a programming language, not a markup language such as HTML.

But yes, it would definately ease some things up.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Setting Image as Background for JFrame. Posted: Jun 14, 2005 7:23 AM
Reply to this message Reply
Found the solution I have Modelled 3 classes:
A ViewPort, An AbstractViewPainter, a BackgroundViewPainter
off this Tutorial:

http://java.sun.com/products/jfc/tsc/articles/swing2d/

Put my JTable in my ViewPort,

myViewPort.setView(myJTable);

and set this ViewPort carrying its own
BackgroundPainter (with my Image)to be the
view port of a ScrollPane in My Application.

myScrollPane.setViewport(myViewPort);

Works like a charm.

Thanks Shannon.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Setting Image as Background for JFrame. Posted: Jun 14, 2005 7:55 AM
Reply to this message Reply
> You have to keep in mind that even though Swing is great
> for building GUIs, Java is a programming language, not a
> markup language such as HTML.
>
> But yes, it would definately ease some things up.


In reference to the above, what in the world does Java
being a Programming language have to do with introducing
and extension to the Components library/API??

Is it that much easier to introduce extensions
to a simple agreed upon document standard? Which
is what the above seems to insinuate.

Jack

Posts: 10
Nickname: zyppora
Registered: Jan, 2005

Re: Setting Image as Background for JFrame. Posted: Jun 15, 2005 12:56 AM
Reply to this message Reply
What I'm saying is that Java is meant to make things functional, not to make things pretty. It was a reply to this piece:

> Thanks man... I'll try it out...
>
> Don't you think it would be great though if Sun
> introduced a method signed:
>
> void setBackgroundImage(Image im)
>
> for Components in the next Java release?

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Setting Image as Background for JFrame. Posted: Jun 15, 2005 2:20 AM
Reply to this message Reply
> What I'm saying is that Java is meant to make things
> functional, not to make things pretty. It was a reply to

If that was the case why do we have a Swing and AWT
library, *practically* everything in Swing that is
done from a functional perspective can be done from
a Console developed program.

Jack

Posts: 10
Nickname: zyppora
Registered: Jan, 2005

Re: Setting Image as Background for JFrame. Posted: Jun 17, 2005 2:57 AM
Reply to this message Reply
If Swing were implemented purely for its aestetics, why is it so hard to set a background image for a JTable?

I see Swing, as compared to the regular GUI toolkit, as a refreshing package of the same thing (with some restrictions). I like it better because it looks different. Boring grey windows get spicy colored, funky designs.

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: Setting Image as Background for JFrame. Posted: Jun 17, 2005 5:35 AM
Reply to this message Reply
You can not be serious man!!

Java is a relatively new language, let alone the
Swing API.

The swing API is *mainly* to provide developers
with a library to create GUIs - Graphical User
Interface (whose sole purpose is to provide User
friendly Interfaces: drop down menus, etc).

Now I say *mainly* because I'm not a Sun Micro
Systems engineer so I have no clue if they had
secondary aspects in mind, but personally and with
most developers I've come across, the Swing library
is used to provide a neat GUI. Functionality
is provided by other AI modules and Controllers.

Really how much functionality does a simple
".getText method provide()" or even at best
an ActionListener, all its doing is toying with
User interaction at a Prettier level (once again
the real functionality lies on the backend - GUIs
provide you with a pretty Front end)...

Flat View: This topic has 9 replies on 1 page
Topic: Question about button action in a gui Previous Topic   Next Topic Topic: Recursion Code I'm having issues with...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use