Slick2d fullscreen adds black bar - java

I am trying to make my java slick2d game fullscreen capable. It launches into fullscreen fine initially with this code:
Container app = new Container(this);
DisplayMode current = Display.getDesktopDisplayMode();
System.out.println(current.getWidth() + "x" + current.getHeight());
Start.setFullscreen(current.getWidth(), current.getHeight());
app.setDisplayMode(Start.FULLSCREEN_WIDTH, Start.FULLSCREEN_HEIGHT, true);
app.setResizable(true);
app.setTargetFrameRate(60);
app.setClearEachFrame(true);
app.setAlwaysRender(false);
app.start();
(The Start class holds a few constant variables that the rest of the program references)
I can also turn off fullscreen in my update method with this code:
if (gc.getInput().isKeyPressed(Input.KEY_ESCAPE)){
if (gc.isFullscreen()){
gc.setFullscreen(false);
} else {
AppGameContainer app = (AppGameContainer)gc;
app.setDisplayMode(Start.FULLSCREEN_WIDTH, Start.FULLSCREEN_HEIGHT, true);
}
}
When I run the program and press escape, it becomes a window and looks fine but when I try to put it back into fullscreen mode, it occupies the whole screen but there is a black bar at the top of the window and the displaying area is squished to whatever size the window was. Here is a screenshot of this effect:
Also, when I switch to fullscreen the console prints INFO:Starting display 1440x900 which is the correct screen size of my display.
I am using a MacBook Air 13-inch running 10.9.2 (Mavericks).

Related

How to hide Taskbar in Fullscreen Mode JavaFx

I am currently writing a Game with JavaFx. I now want to make the game run in fullscreen mode. I have written the following code:
public class Game extends Application {
public static void main(String[] args){
launch(args);
}
#Override
public void start(Stage gameStage) {
gameStage.setResizable(false);
gameStage.setMaximized(Settings.fullscreen);
gameStage.setFullScreen(Settings.fullscreen);
Settings.changeRoot(StartMenu.getInstance()); //this line just sets my root element
Scene scene = new Scene(Settings.root,Settings.width,Settings.height);
gameStage.setScene(scene);
SoundLoader.getInstance(); //loads sound
ImageLoader.getInstance(); //loads all ingame images
gameStage.show();
}
}
The proplem was that it allways showed a popup that said press esc to leave fullscreen mode. I added the following line to remove that text:
gameStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
The problem now was, that it no longer goes completly into fullscreen mode it allways showes the Toolbar screenshot that shows how the game is displayed.How can I hide the taskbar completly?
I figured out that the game application wasnt in the front that was the reason why the toolbar was infront of it. i added the following line to fix it:
gameStage.toFront();
You can remove the text/popup of Press ESC to leave FullScreen this way :
gameStage.setFullScreenExitHint("");
PS : Remove the line you added (gameStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH); Because I guess this way you won't have to hide any Taskbar.

java 1.8+ Full-Screen Exclusive Mode setFullScreenWindow(Frame) strange behavior

I'm working on a fullscreen application and discovered some really weird behavior using setFullScreenWindow(Frame) to actually get the application frame to fullscreen exclusive mode on some notebooks. While my code works on most WinOS systems on some it just doesn't. The resolution change works but the application stays in the top left corner of the screen in its former resolution like the setFullScreenWindow(Frame) call did not actually work. No exception thrown. If I connect a second display to the system and make it primary display it suddenly works. If I disconnect the second display and run the app on the previous used native display it also now suddenly works. If I reboot the system the native display again fails to bring the app to fullscreen. Both isFullScreenSupported() and isDisplayChangeSupported() are true in any cases.
Strange. Notebook is a MacBookPro with a Bootcamp WinOS10 installation but problem is not limited to this hardware or WinOsVersion.
client.windowScale = 2;
client.setVisible(false);
client.setResizable(false);
client.setUndecorated(true);
client.setSize(RES_WIDTH * client.windowScale, RES_HEIGHT * client.windowScale);
DisplayMode newDisplayMode;
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode_Old = gd.getDisplayMode();
if (gd.isFullScreenSupported() & gd.isDisplayChangeSupported()) {
gd.setFullScreenWindow(client);
gd.setDisplayMode(
new DisplayMode(
RES_WIDTH * client.windowScale,
RES_HEIGHT * client.windowScale,
DisplayMode_Old.getBitDepth(),
DisplayMode_Old.getRefreshRate()));
}
else {
System.out.println("Fullscreen failed.");
}
}
Actual Image:

How to get current active window while running my java application

I need to get current active window.
I have used KeyboardFocusManager, for getting active window. But i am getting active window is null.
below is the code.
please provide any way to get current active window.
KeyboardFocusManager currentManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Window activeWindow = currentManager.getActiveWindow();
This single line of code should work:
Window activeWindow = javax.swing.FocusManager.getCurrentManager().getActiveWindow();
from the JavaDoc:
Returns the active Window, if the active Window is in the same context
as the calling thread. Only a Frame or a Dialog can be the active
Window. The native windowing system may denote the active Window or its
children with special decorations, such as a highlighted title bar.
The active Window is always either the focused Window, or the first
Frame or Dialog that is an owner of the focused Window.
to get the GlobalActiveWindow, call:
javax.swing.FocusManager.getCurrentManager().getGlobalActiveWindow();
JavaDoc:
Returns the active Window, even if the calling thread is in a different context than the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.
Note:
When your application does not have the focus, this method returns null!
Cheers!
Found the following code and it worked fine for me:
Window getSelectedWindow(Window[] windows) {
Window result = null;
for (int i = 0; i < windows.length; i++) {
Window window = windows[i];
if (window.isActive()) {
result = window;
} else {
Window[] ownedWindows = window.getOwnedWindows();
if (ownedWindows != null) {
result = getSelectedWindow(ownedWindows);
}
}
}
return result;
}
And you can call it like this using the static method of class Window:
Window w = getSelectedWindow(Window.getWindows());
Good Luck.
Almost forgot to mention, I've found the recursive method in this site.

Java full screen exclusive mode

I made my application to be full screen in exclusive mode but when I show an input dialog the application is minimized. I want the application to stay full screen and the input dialog to be show over it.
This is how I render my application full screen:
setUndecorated(true);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
gs.setFullScreenWindow(this);
validate();
Edit:
This is how I open the dialog:
JOptionPane.showMessageDialog(StartingPoint.this,txt, "You are on: " + planet, JOptionPane.INFORMATION_MESSAGE, icon);
but when I show an input dialog the application is minimized
1) I can't to simulating this issue and simly isn't possible without additional code iconofied for Full-Screen Application
2) please to check Programming Tips about AWT/Swing
3) setParent (not possible corectly for JFrame) for input dialog
4) to check if isn't there more than one Top-level Container with setModal / ModalityTypes

How does NetBeans' Splash Screen feature work?

New to NetBeans and just noticed that in the File >> Project Properties >> Application dialog there is a text field labeled Splash Screen that allows you to specify a path to an image that you would like displayed when your program is launching.
I want to customize the way my splash screen works (adding a progress bar, etc.) and would like to code it from the ground up but don't know where to start. What are the best practices for Java/Swing-based splash screens?
Thanks for any and all input!
The project properties -> Application -> Splash Screen allows you to add an image to an application. This property sets a value in the MANIFEST.MF called SplashScreen-Image: e.g. SplashScreen-Image: META-INF/GlassFish316x159.jpg This property will automatically cause the image to display as a splash screen. It does not work inside NetBeans, and must be run outside the IDE.
There is a tutorial Splash Screen Beginner Tutorial that details how to use it more detail. The tutorial was done for NetBeans 6.8, but will work on 7.2.1 which is the latest at the time of this post.
I'm not sure how NetBeans does it, but Splash Screens are supported by the JRE since version 6. See http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/
Splash screen is just a instance of java.awt.Window or undecorated javax.swing.JFrame.
To create window just say new Window(null), then set size and position (using tookit you can calculate where the screen center is) and then say window.setVisible(true)
Due to this is your own window you can do what you want: set layout, image, add process bar to the SOUTH etc.
You can also use JFrame: new JFrame().setUndecorated(true)`
There are a couple of ways to do this.
To do a simple splash screen (an image) you can specify this in the command line of you java application.
Here is a simple example
java -splash:<file name> <class name>
However, if you want a progress bar, you are going to have to do something a little more complicated, and write some code yourself. This is done in the following way.
Create a JWindow (or Window or undecorated JFrame) component with your splash screen elements
Set it to visible
Do the rest of your Swing GUI startup code
Set your JFrame to visible, then immediately follow with setting the JWindow to visible(false)
This should show the splash almost immediately, and then hide once the your application is fully loaded.
To see some splash screen code, take a look here. The implementation in the link only shows how to achieve what you can with the -splash command, but it will give you a good start to also include the progress bar that you requested.
I hope this helps you, it is a small example of how to create yourself a simple splash screen using a dummy Progress Bar:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class SplashScreen extends JWindow
{
private static JProgressBar progressBar = new JProgressBar();
private static SplashScreen execute;
private static int count;
private static Timer timer1;
public SplashScreen()
{
Container container = getContentPane();
container.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new javax.swing.border.EtchedBorder());
panel.setBackground(new Color(255,255,255));
panel.setBounds(10,10,348,150);
panel.setLayout(null);
container.add(panel);
JLabel label = new JLabel("Hello World!");
label.setFont(new Font("Verdana",Font.BOLD,14));
label.setBounds(85,25,280,30);
panel.add(label);
progressBar.setMaximum(50);
progressBar.setBounds(55, 180, 250, 15);
container.add(progressBar);
loadProgressBar();
setSize(370,215);
setLocationRelativeTo(null);
setVisible(true);
}
public void loadProgressBar()
{
ActionListener al = new ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
count++;
progressBar.setValue(count);
if (count == 50){
timer1.stop();
execute.setVisible(false);
//load the rest of your application
}
}};
timer1 = new Timer(50, al);
timer1.start();
}
public static void main (String args[]){
execute = new SplashScreen();
}
}
Cheers!
Also consider to build your application on top of the NetBeans Platform (a Swing-based RCP). One of the many benefits: it comes with a customizable splash screen with progress bar.
Sample progress bar:
http://platform.netbeans.org/tutorials/nbm-paintapp.html#wrappingUp
Port a Swing application to the NetBeans Platform:
http://platform.netbeans.org/tutorials/60/nbm-porting-basic.html
Further links:
http://netbeans.org/features/platform/index.html
http://netbeans.org/features/platform/all-docs.html
If your application is build using NetBeans Platform, then here's a tutorial about splash screen customisation: http://wiki.netbeans.org/Splash_Screen_Beginner_Tutorial
There is a sample Javafx equivalent of Splash screen. However this splash screen is basically a java swing applet that is called from javafx to be displayed to the user and simulates more or less eclipse and netbeans splash screen using progress bar and titles for the loaded contents. This is the link.
You must be able to get the code and separate out the splash screen code written in java swings and use it for yourself.
This is a custom java swings splash screen. and hence to center the splash screen it uses the traditional
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension labelSize = l.getPreferredSize();
setLocation(screenSize.width / 2 - (labelSize.width / 2),
screenSize.height / 2 - (labelSize.height / 2));

Categories

Resources