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

