Not the usual HeavyWeight/LightWeight question

I know all about Swing being lightweight and you shouldn't mix

heavyweight components. I tried to use the infamous

JPopupMenu.setDefaultLightWeightPopupEnabled(false);

with success other than the fact that my Java 1.3, 1.3.1 on my

linux box would crash all the time when accessing the now

heavyweight menus. So here is the issue.Is it possible to

get drawn graphics (like g.drawLine) to be put out below the

lightweight popups? If so how?

Here is some of my code to explain the situation better. I am

very new to Java so my OOP is a little lacking....

It's a gui with a large panel in the Center for drawing stuff.

Here's the main JFrame with it's constructor:

public class asdf extends JFrame implements ActionListener,

MouseListener, KeyListener,

MouseMotionListener,

Globalparams,

SwingConstants,ChangeListener

{

ImpairToolBar impairtoolbar = newImpairToolBar(JToolBar.VERTICAL,this);

ModToolBar modifiertoolbar = newModToolBar(JToolBar.VERTICAL,this);

guiMenuBar menubar;

int x=-999,y=-999;

int pressedx=-999,pressedy=-999;

JPanel emulationPane = new JPanel();

JPanel workPane = new JPanel();

public asdf() {

super("asdf");

Container contentpane = getContentPane();

//For now leave the popupMenu lightweight, making menus heavyweight

//apparently causes the crashes of the GUI we have been seeing

Global.popupmenu = new guipopupMenu();

menubar = new guiMenuBar(this);

//Make the menus all HEAVYweight so they appear ABOVE everything else

//JPopupMenu.setDefaultLightWeightPopupEnabled(false);

setBackground(Color.white);

emulationPane.setBackground(Color.white);

emulationPane.setLayout(new BorderLayout());

workPane.setBackground(Color.white);

emulationPane.add(workPane,BorderLayout.CENTER);

setJMenuBar(menubar);

contentpane.add(emulationPane);

emulationPane.addMouseListener(this);

emulationPane.addMouseMotionListener(this);

pack();

}

Here's it's Paint method:

public void paint(Graphics g)

{

super.paint(g);

refreshScreen(g,false); //this redraws all the lines and icons

//on the screen so when a menu

//is accessed and Java calls "update"

//the graphics get redrawn

}

}

Here's a class "Lines" which draws lines whose "paint" is called from "refreshScreen" above.

public class Lines implements Globalparams

int fromX;

int fromY;

int toX;

int toY;

public Lines( int fromX, int fromY, int toX, int toY)

{

this.fromX = fromX;

this.fromY = fromY;

this.toX = toX;

this.toY = toY;

}

public void paint(Graphics g )

{

g.drawLine(this.fromX,this.fromY,this.toX,this.toY);

}

Now by redrawing the lines with the "paint" above everytime

the menus are accessed, the lines (and other stuff which is

put out similiarly) are put out ABOVE or at the same level as

the menus.If you move down the menu list, the items will appear

above the drawn icons and lines but othewise they are above

the menu items.

If I don't redraw the line/icons every time Java calls "update" then

the graphics obviously disappear, if they are under the menu items,

until I refresh the screen.

Am I going about this completely wrongly? If so, what is the

solution?

THanks for any help,

Chip

[3607 byte] By [chippr] at [2007-9-26 4:21:02]
# 1

Chip,

IMHO, you're not going about this in the right way. Your main class implements seven interfaces; while this is certainly possible, it generally means that you're making the class "wear too many hats." As far as the code you've posted goes, it doesn't appear that most of them are necessary; in fact, since I don't see any of the methods that you're required to implement when you implement the interfaces, I'm not sure if your code is even compiling (but I realize you may have left some out for the sake of brevity).

I'd take a crack at compiling it and playing with it a little to see if I could duplicate your problem (and suggest a solution), but I think I'd need all the source code, as this doesn't seem complete.

Also, for those here who are better at just reading the code and figuring out how it works (and there are a lot who are much better at it than I am), it would really help if you would start the code snippen with a ["code"] tag and end it with a ["/code"] tag. If you use those tags (without the double quotes), the code comes out nicely formatted, like this:

public class asdf extends JFrame {

public asdf() {

// Do something.

}

}

Rich

rmiller1985 at 2007-6-29 17:24:44 > top of Java-index,Archived Forums,Java Programming...
# 2

Hi Rich,

Yes what I gave is only a extremely small part of my code.

The entire gui is 15-20,000 lines.I certainly didn't want to

post even the part that this problem deals with. I was just trying

to give an idea of what I am doing and what I am trying to do.

Thanks

Chip

chippr at 2007-6-29 17:24:44 > top of Java-index,Archived Forums,Java Programming...