JavaFX Real Fullscreen on macOS - macos

I want a javafx.stage.Stage to be in fullscreen mode on macOS with no (native) menu bar visible. Also I want that the dock is not available while the application is in fullscreen mode.
I have a Stage and I set stage.setFullScreen(true). If the style of my stage is set to stage.initStyle(StageStyle.UNDECORATED), the application displays the native menu bar and the dock. Therefore the whole screen isn't available for the application.
If I set the style to stage.initStyle(StageStyle.UTILITY) the menu bar is not visible, but instead there is a grey area.
And if I move the cursor where usually the menu bar is placed, the menu bar will show itself additionally with a small closing button and a small bar.
Also If I cursor the mouse down where the dock is placed, the dock will show up itself.
How can I achieve a real fullscreen application with no menubar and no dock displayed and no grey bar at the top so my application can use all of the screen size?
Code
import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Fullscreen extends Application {
#Override public void start(Stage stage) throws Exception {
AnchorPane pane = new AnchorPane();
Scene scene = new Scene(pane);
pane.setStyle("-fx-background-color: blue");
stage.initStyle(StageStyle.UTILITY);
stage.setFullScreen(true);
stage.setScene(scene);
stage.show();
//stage.setHeight(stage.getHeight() + 16);
//stage.setY(-16);
}
}
Annotation
If I set stage.setHeight(stage.getHeight() + 16) and stage.setY(-16) after stage.show() and the style is set to stage.initStyle(StageStyle.UTILITY), the grey bar isn't visible anymore. But this seems not to be a good solution for me because it depends on the screen size (in my case 2560x1440) and I don't know how to exactly get the size of the grey bar. Also the menubar and the dock are available.

Using Stage#setFullScreen(boolean) is the correct way. When I run this MWE, I get the expected OS X full screen (no dock, automatically hidden menu bar):
public class FullScreenDemo extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(final Stage primaryStage) {
primaryStage.setFullScreen(true);
primaryStage.setScene(new Scene(new Label("Foo")));
primaryStage.show();
}
}
I don't think you can get rid of the native menu bar that pops up when you hover over its position—that's just how the OS behaves. The corresponding Javadoc also states:
The implementation of full-screen mode is platform and profile-dependent.

Related

MudBlazor: how to display notification in Bottom-Right of window?

I have created an app using MudBlazor template.
All is ok, I use MudBlazor Snackbar and in MainLayout I use
and button on it.
On click I call a function
ShowNotification("BottomRight")
private void ShowNotification(string position)
{
Snackbar.Clear();
Snackbar.Configuration.PositionClass = position;
Snackbar.Add(message, Severity.Normal);
}
I'd like to show notifications in the Bottom-Right of the Browser window but it displayed in left top corner because it is MudAppBar.
How to display notification in the Bottm-right of browser window?
You should not be using "BottomRight" but Defaults.Classes.Position.BottomRight instead:
#inject ISnackbar Snackbar
<MudButton
OnClick="#this.ShowMessage"
Color="Color.Success">
Show message
</MudButton>
#code {
void ShowMessage()
{
this.Snackbar.Clear();
this.Snackbar.Configuration.PositionClass = Defaults.Classes.Position.BottomRight;
this.Snackbar.Add("Wazzup?", Severity.Normal);
}
}
Demo: https://try.mudblazor.com/snippet/wumnYmbNHjwLplPt

Adding Icon on a button on NetBeans

I have a problem whereby I can seem to be unable to see my icon image on the button on NetBeans. It works very well on Eclipse by showing button text with the icon, but when I move the code to NB it does not display the icon just the text. Could someone help me with this problem.
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
public class MyFrame extends JFrame implements ActionListener{ //implements allows the button to perform action
JButton button = new JButton(); //making a button global. Declare outside the contructor
MyFrame(){
ImageIcon icon = new ImageIcon("icon.png");//adding an Icon
button = new JButton();
button.setBounds(200, 100, 200, 100);//poistion and size
button.addActionListener(this); //To make the button work, so it display what you need to display
button.setText("CLICK ME"); //Set text to the button
button.setFocusable(false); //Removes the border aroound the button text
button.setIcon(icon); //Adding icon to a button
button.setHorizontalTextPosition(JButton.CENTER); // setting alignment for the button
button.setVerticalTextPosition(JButton.BOTTOM);
button.setFont(new Font("Comic Sans", Font.BOLD,25)); //setting font for the button
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
this.setSize(500,500);
this.setVisible(true);
this.add(button);
}
//METHOD FOR ACTION LISTENER
#Override
public void actionPerformed(ActionEvent e){
if(e.getSource()==button){ //to check event occours with our button
System.out.println("YESSIR"); //displaying what I want when I click the button
}
}
The icon file cannot be found. Assuming your image is stored under src/main/resources/icons/icon.png you would load it with:
ImageIcon icon = new ImageIcon(getClass().getResource("/icons/icon.png");

Create a Sizeable Draggable Pane in JavaFX 8

I am attempting to create a "workspace" where users can open several containers to display distinct information. These need to be moveable and sizeable (ScrollPane for example).
I have successfully created the majority of the functionality - however one thing is really causing me issues and I am not able to figure out the issue.
I created the following class:
public class WorkspaceMoveableSizeablePane extends Pane
public WorkspaceMoveableSizeablePane(Node view) {
getChildren().add(view);
init();
}
private void init() {
...set up the event handlers....
I attempt to use this pane by wrapping an existing pane like so in my WorkspaceController:
#FXML private openSampleWorkspaceNode() {
FXMLLoader loader = new FXMLLoader();
Parent node = loader.load(
this.getClass().getResource("MyView.fxml").openStream());
WorkspaceMoveableSizeablePane dn = new WorkspaceMoveableSizeablePane(node);
pane.getChildren().add(dn);
}
When I open it this way - I can size my Pane and drag it, however the children on the "node" which is an anchor pane stay in their current positions rather than get hidden.
To correct this issue, I wrapped the AnchorPane in a ScrollPane in the FXML file. This allowed the resize to happen - and as expected the portions out of bounds were not visible and the scrollbars appeared, however the drag stopped. When I attempted to track the mouse dragged event, it actually didn't fire unless I was resizing the WorkspaceMoveableSizeablePane.
//Event Listener for MouseDragged
onMouseDraggedProperty().set(event -> {
System.out.println("You are in the Mouse Dragged Event");
if(isTopSelected){
dragPaneToNewLocation(event);
}else if(isResizingHeight) {
handleResizeHeight(event);
}else if(isResizingWidth) {
handleResizeWidth(event);
}
});
I reverted my FXML to AnchorPane and changed the WorkspaceMoveableSizeablePane as follows to see if that would help:
public class WorkspaceMoveableSizeablePane extends ScrollPane
public WorkspaceMoveableSizeablePane(Node view) {
setContent(view);
init();
}
private void init() {
...set up the event handlers....
As before the resize worked, but the drag didn't. The mouse dragged event never fired. Additionally, my scroll pane was blank with nothing in it.
So I am at a loss on how to proceed with this attempt.
Is there a limitation on the event handlers of the ScrollPane? Is there a different event I should be listening for? Thanks!!
The issue was that the ScrollPane was trapping the MouseDragged event.
Added an Event Filter and all is good...
addEventFilter(MouseEvent.MOUSE_DRAGGED, event -> {
if(isTopSelected){
dragPaneToNewLocation(event);
}else if(isResizingHeight) {
handleResizeHeight(event);
}else if(isResizingWidth) {
handleResizeWidth(event);
}
});

JavaFX title bar RTL not supported?

I cant seem to find a way of making the title bar of my window be RTL.
I can make the inner nodes RTL by changing the node orientation property, but not the title bar.
So I get a really weird looking app where everything is RTL except the title bar.
How can I fix this?
You need to invoke setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT) on the scene before showing the stage primaryStage.show():
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
Scene scene = new Scene(root, 300, 275);
primaryStage.setScene(scene);
scene.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
See Node Orientation in JavaFX:
Because the orientation of children might be different for each child, the orientation of a child node when explicitly set can override the parent. For example, the top level window might be right-to-left, with the title and close box appearing on the left.
Just like what #Eng.Fouad said for scene object can be done for menubar.
Invoking
setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT)
for the menubar object makes it rtl:
MenuBar menuBar = new MenuBar();
menuBar.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
except that the arg for this method can be
NodeOrientation.LEFT_TORIGHT
which makes it left to right and
NodeOrientation.INHERIT
that gets its value from the parent container.

Text and Image on SWT Button

Is there a way to have a SWT buuton with both image and text in a view? I have tried embedding Swings in SWT and the view looks exactly as I want, but when there is an operation going on, this view doesnot load till it gets over. This makes my perspective look unstable. Please help.
What OS are you using? On Windows XP/Vista/Windows 7, GTK+ and OSX you can just set the text and the image. E.g.
public class ButtonView extends ViewPart
{
private Button m_button;
public void createPartControl(Composite parent)
{
m_button = new Button(parent, SWT.NONE);
m_button.setText("My Button");
m_button.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR));
}
public void setFocus()
{
m_button.setFocus();
}
}

Resources