I thought I'd give everybody an update. To fix the problem, all
you have to do is add the indicated two lines (how easy is that?):
private InternalFrameListener listener=new
> InternalFrameListener() {
> internalFrameActivated(internalFrameEvent e) {
> if(toggle) {
> toggle=false;
> mainFrame.setJMenuBar(menu1);
> } else {
> toggle=true;
> mainFrame.setJMenuBar(menu2);
> }
frame.validate(); //new
frame.repaint(); //new
> }
> ...
> }
Steve Barrett <[EMAIL PROTECTED]> on 06/27/2001 05:59:27 PM
Sent by: Steve Barrett <[EMAIL PROTECTED]>
To: KC Eilander/MTN/US/3Com
cc:
Subject: Re: JMenuBar Problem.
I do this with jdk1.3 and haven't had any trouble, but I only replace
the menu column on the menubar, not the whole menu bar. I have seen
lots of odd repaint problems though and this may be related.
Specifically in jdk11.3 if I am trying to change something from an
event driven method (like yours) I almost always have to perform the
action by doing something like:
// in internalFrameActivated()
SwingUtilities.invokeLater(new Thread() {
public void run () {
> if(toggle) {
> toggle=false;
> //mainFrame.remove(menu2); //doesn't help
> mainFrame.setJMenuBar(menu1);
> } else {
> toggle=true;
> //mainFrame.remove(menu1); //doesn't help
> mainFrame.setJMenuBar(menu2);
> }
}});
I realize the code you included is probably just a snippet but
menu1 can't be both a menubar and a menu and frame.remove() won't
work because the menubar is actually not in the JFrame but in the
container inside the frame which holds the menubar, glasspane and
contentpane.
--- [EMAIL PROTECTED] wrote:
>
>
>
> I have an MDI application with which I want to
> switch the menubar of the desktop pane depending on
> which window is active. In the following version of my test app,
> the toggling works, and Menu1 shows up fine on its turn, but
> garbage pixels show up for Menu2 on its turn...
>
>
> class whatever {
> JDesktopPane desktop=new JDesktopPane();
> JMenuBar menu1=new JMenuBar();
> JMenuBar menu2=new JMenuBar();
> JMenu menu1=new JMenu("menu1");
> JMenu menu2=new JMenu("menu2");
>
> private InternalFrameListener listener=new
> InternalFrameListener() {
> internalFrameActivated(internalFrameEvent e) {
> if(toggle) {
> toggle=false;
> //mainFrame.remove(menu2); //doesn't help
> mainFrame.setJMenuBar(menu1);
> } else {
> toggle=true;
> //mainFrame.remove(menu1); //doesn't help
> mainFrame.setJMenuBar(menu2);
> }
> //frame.repaint(); // doesn't help
> }
> ...
> }
>
> main() {
> ...
> mainFrame.setContentPane(desktop); // where mainFrame is
> just my
> application frame
> mainFrame.setJMenuBar(menu1);
> ...
> }
> };
>
>
> _______________________________________________
> Swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/swing
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing