Does Modern Docking allow embedded jmenubar in the frame title bar? #219
-
i'm trying to move the main menu bar into the frame title bar to increase window real estate. Is this doable? I have fiddled with the flatlaf settings but no luck yet. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Beta Was this translation helpful? Give feedback.
-
Hmm, I am doing this with flatlaf without any issues. It was just setting the single flatlaf setting and it worked. |
Beta Was this translation helpful? Give feedback.
-
Here is a minimum test case. it is based on one of the examples. The only change is to add FlatLightLaf and a JMenuBar. the bar is not on the top of the JFrame. import ModernDocking.Dockable;
import ModernDocking.DockableStyle;
import ModernDocking.DockingRegion;
import ModernDocking.app.AppState;
import ModernDocking.app.Docking;
import ModernDocking.app.RootDockingPanel;
import ModernDocking.exception.DockingLayoutException;
import com.formdev.flatlaf.FlatLightLaf;
import javax.swing.*;
import java.awt.*;
import java.io.File;
/**
* Creates a modern docking frame with some windows and a menu bar while using the FlatLightLaf theme.
*/
public class ModernDockingMenuTest extends JFrame {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
ModernDockingMenuTest example = new ModernDockingMenuTest();
example.setVisible(true);
});
}
public ModernDockingMenuTest() {
// common Java Swing setup
setTitle("Basic Modern Docking Example"); // <-- typo in the original fixed
setSize(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationByPlatform(true);
setLocationRelativeTo(null);
setLookAndFeel(); // <-- new
// create the single Docking instance for the life of the program
Docking.initialize(this);
// set the auto persist file
// auto persist is off by default and we will leave it that way until we're done configuring the default layout
// that way we're not persisting the default layout and overwriting the file before we load the file
AppState.setPersistFile(new File("example_layout.xml"));
// restore the layout from the auto persist file after the UI has loaded
SwingUtilities.invokeLater(() -> {
try {
AppState.restore();
}
catch (DockingLayoutException e) {
e.printStackTrace();
}
// now that we've restored the layout we can turn on auto persist
AppState.setAutoPersist(true);
});
Panel panel1 = new Panel("one");
Panel panel2 = new Panel("two");
Panel panel3 = new Panel("three");
Panel panel4 = new Panel("four");
// create the root panel and add it to the frame
RootDockingPanel rootPanel = new RootDockingPanel(this);
add(rootPanel, BorderLayout.CENTER);
// dock our first panel into the center of the frame
Docking.dock(panel1, this);
// dock the second panel to the center of the first panel
Docking.dock(panel2, panel1, DockingRegion.CENTER);
// dock the third panel to the east of the second panel
Docking.dock(panel3, panel2, DockingRegion.EAST);
// dock the fourth panel to the frame south
Docking.dock(panel4, this, DockingRegion.SOUTH);
// new: add menu bar
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
item.addActionListener(e -> System.exit(0));
menu.add(item);
bar.add(menu);
setJMenuBar(bar);
}
private void setLookAndFeel() {
try {
UIManager.setLookAndFeel(new FlatLightLaf());
// option 2: UIManager.setLookAndFeel(new FlatDarkLaf());
} catch (Exception ignored) {}
}
// all dockables must be at least Component
public static class Panel extends JPanel implements Dockable {
private final String name;
public Panel(String name) {
this.name = name;
// register the dockable with the Docking framework in order to use it
Docking.registerDockable(this);
}
@Override
public String getPersistentID() {
return name;
}
@Override
public int getType() {
return 0;
}
@Override
public String getTabText() {
return name;
}
@Override
public Icon getIcon() {
return null;
}
@Override
public boolean isFloatingAllowed() {
return false;
}
@Override
public boolean isLimitedToRoot() {
return false;
}
@Override
public DockableStyle getStyle() {
return DockableStyle.BOTH;
}
@Override
public boolean isClosable() {
return false;
}
@Override
public boolean isPinningAllowed() {
return false;
}
@Override
public boolean isMinMaxAllowed() {
return false;
}
@Override
public boolean getHasMoreOptions() {
return false;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Locking this discussion because it keeps getting spammed by random accounts. Guess we'll see if they move to another one. |
Beta Was this translation helpful? Give feedback.
Oh no, it was me the whole time.... the look and feel has to be set before the jframe is created! :(