Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-27-2005, 06:47 PM   #1
LQ Newbie
Registered: Oct 2005
Posts: 1

Rep: Reputation: 0
JAVA: Graphics problem

ok, I may be a to this forum, but I'm not a newbie to Linux nor Java.

That being said, I have a problem with ActiveRendering on Linux. At home I have a Mac (running Tiger - 10.4) and it runs the program well. I do have to resize the window to get it to display anything but it still works. In Linux, no matter what I do, it displays nothing.

I have been modifying code that did work considerably well, it was just not as efficient. The main problem was that some of our components need to render themselves first before they can know their exact width and height. So, when the Components are added to the TopWindow (which actually contains a JFrame) it needs to call their render(Graphics2D) method. The problem with being able to do this is that I need to create the JFrame, pack it, and then JFrame.setVisible(false). Somehow, the Graphics and BufferStrategy get disconnected with the global JFrame in TopWindow. Here's some code:

This is in the Constructor:
visible = false;
container = new JFrame(title);
strategy = container.getBufferStrategy();
g2d = (Graphics2D) strategy.getDrawGraphics();

public void add(Component element) {

I thought that maybe the problem lay in the fact that the graphics are never disposed of nor the strategy shown. But in renderAll() (the call made when we just want to re-render everything, such as on resizing or moving the window) if I dispose of the graphics and show the strategy, it still doesn't work. I do have mouseListeners and ActionListeners set correctly with the TopWindow as the parent of all the Components, and they work. Also, before actually displaying the window but aftert all the elements are added to it, I have these lines:

container.setBounds(this.alignmentX, this.alignmentY, this.width,

// Disable repainting to be able to use accelerated-mode


// automatically renders when resized or moved

Help! This is for a class and it's really bad if you have to say, "Oh, don't worry about not seeing anything, it's all there, just imagine it." I don't think they'll accept that.
Old 10-28-2005, 11:37 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Are you - or would you consider - overriding the "update()" method, and having it call "paint()":

public void update(Graphics g) {
paint (g);

And if you're not already doing it, double-buffering might solve the problem ... and give you a much speedier, cleaner display to boot. Here's one example:

'Hope that helps .. PSM


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
graphics with java simcox1 Mandriva 3 04-02-2005 12:55 PM
java Graphics[2D] requires an X server? Cand1e Programming 12 02-18-2004 08:18 AM
Java Graphics in Linux hiteshmaisheri Linux - Software 10 02-08-2004 11:39 AM
graphics problem d_lake Linux - General 1 03-11-2003 07:46 PM
Graphics problem frkstein Linux - General 6 02-22-2002 07:50 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:55 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration