Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MenuBar issue (custom decorations, JetBrains Runtime 11) #151

Closed
remcopoelstra opened this issue Aug 4, 2020 · 3 comments
Closed

MenuBar issue (custom decorations, JetBrains Runtime 11) #151

remcopoelstra opened this issue Aug 4, 2020 · 3 comments
Labels
custom window decorations Related to using FlatLaf custom window decorations JetBrains Runtime Related to using JetBrains Runtime (JBR)
Milestone

Comments

@remcopoelstra
Copy link

In my application menu's are added and removed dynamically, while implementing the FlatDarculaLaf with custom (native) decorations using jbr-11_0_7 I noticed a strange issue. When adding a menu after the frame was minimized/restored the new menu doesn't respond to mouse move/clicks.

Maybe this is a bug in the JetBrains Runtime or perhaps I am not using the correct method for revalidating the MenuBar but I decided to write a small application demonstrating this behavior.

I am using release 0.39 and a HiDPI display scaled at 200%.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import com.formdev.flatlaf.FlatDarculaLaf;

public class MenuTest {

	enum State {
		FRAME_SHOWN,
		MENU_REMOVED,
		FRAME_MINIMIZED,
		FRAME_RESTORED,
		MENU_ADDED,
		DONE
	}
	State state = State.FRAME_SHOWN;
	Timer timer;


	public MenuTest() {

		try {
			UIManager.setLookAndFeel(new FlatDarculaLaf());
			JFrame.setDefaultLookAndFeelDecorated(true);
			JDialog.setDefaultLookAndFeelDecorated(true);
		} catch (UnsupportedLookAndFeelException e) {
			e.printStackTrace();
		}

		JFrame frame = new JFrame("JFrame");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(850, 650);

		JMenuBar menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);

		JMenu firstMenu = new JMenu("File");
		firstMenu.add(new JMenuItem("Exit"));
		menuBar.add(firstMenu);

		JMenu secondMenu = new JMenu("Help");
		secondMenu.add(new JMenuItem("About"));
		menuBar.add(secondMenu);

		frame.setLocationRelativeTo(null);
		frame.setVisible(true);

		timer = new Timer(1000, new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				switch (state) {
				case FRAME_SHOWN:

					menuBar.remove(1);
					menuBar.revalidate();
					menuBar.repaint();

					state = State.MENU_REMOVED;
					break;

				case MENU_REMOVED:
					frame.setExtendedState(JFrame.ICONIFIED);
					state = State.FRAME_MINIMIZED;
					break;

				case FRAME_MINIMIZED:
					frame.setExtendedState(JFrame.NORMAL);
					state = State.FRAME_RESTORED;
					break;

				case FRAME_RESTORED:

					JMenu secondMenu = new JMenu("Help");
					secondMenu.add(new JMenuItem("About"));
					menuBar.add(secondMenu);

					menuBar.revalidate();
					menuBar.repaint();

					state = State.MENU_ADDED;
					break;

				case MENU_ADDED:
					timer.stop();
					state = State.DONE;
					break;

				default:
					break;
				}

			}
		});
		timer.setRepeats(true);
		timer.start();

	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				new MenuTest();
			}
		});
	}

}
@DevCharly
Copy link
Collaborator

Thx for reporting. This is a bug in FlatLaf, which has to tell the JBR which areas in the title area it should ignore (menubar, buttons and icon). This is probably not done correctly when the menu bar is modified. I'll have a look...

DevCharly added a commit that referenced this issue Aug 6, 2020
… events after adding menus and when running in JetBrains Runtime (issue #151)
@DevCharly
Copy link
Collaborator

fixed in master branch

@DevCharly DevCharly added this to the 0.40 milestone Aug 6, 2020
@remcopoelstra
Copy link
Author

Great! I just tested the master branch with my application and I can confirm it's fixed now.

Thanks!

@DevCharly DevCharly added the JetBrains Runtime Related to using JetBrains Runtime (JBR) label Sep 18, 2020
@DevCharly DevCharly added the custom window decorations Related to using FlatLaf custom window decorations label Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom window decorations Related to using FlatLaf custom window decorations JetBrains Runtime Related to using JetBrains Runtime (JBR)
Projects
None yet
Development

No branches or pull requests

2 participants