понедељак, 14. јануар 2019.

Java Swing GUI Application Full Screen on Linux

How to make your Java Swing application full screen on Linux

I have found this code on the stack overflow site:

static public boolean fullScreen(final JFrame frame, boolean doPack) {

  GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
  boolean result = device.isFullScreenSupported();

  if (result) {
    frame.setUndecorated(true);
    frame.setResizable(true);

    frame.addFocusListener(new FocusListener() {
      @Override
        public void focusGained(FocusEvent arg0) {
          frame.setAlwaysOnTop(true);
}

        @Override
        public void focusLost(FocusEvent arg0) {
          frame.setAlwaysOnTop(false);
        }
    });

    if (doPack)
      frame.pack();
      device.setFullScreenWindow(frame);
    } else {
      frame.setPreferredSize(
        frame.getGraphicsConfiguration().getBounds().getSize());


      if (doPack)
        frame.pack();

      frame.setResizable(true);

      frame.setExtendedState(Frame.MAXIMIZED_BOTH);
      boolean successful = frame.getExtendedState() == Frame.MAXIMIZED_BOTH;

      frame.setVisible(true);

      if (!successful)
          frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    }
    return result;
}

This is important peace of code if you want to make a full screen application that works the same on both Linux and Windows OS.

For example, if you just write this:

setExtendedState(JFrame.MAXIMIZED_BOTH);
setUndecorated(true);

... the code above would make a full screen on Windows, but on Linux you would still see the task bar:


The code that I found on the stack overflow makes a full screen on both Windows and Linux:


At the top of the screen, you can see burnt in pixels from the previous version of software which did not do the full screen (it had the task bar on it).


Read only File System on Raspberry Pi

How to make the file system of the Raspberry Pi read only

There is an update to this story: https://mvidakovic.blogspot.com/2019/08/the-ultimate-read-only-file-system-on.html

I have found this repo on the gitlab and decided to fork it:
https://github.com/milanvidakovic/rpi-readonly

Why is this important? Well, Raspberry Pi usually uses micro SD card as a drive. I have been using Raspberry Pi and similar computers since 2014 and have seen SD card crashes too many times. Last time, my RPI2 crashed on regular poweroff (sudo poweroff). The SD card in it was new, so it was not the old faulty card. Simply, RPI tends to crash SD cards. Sooner or later, it will crash it.

There are numerous tutorials on how to make Raspbian file system read only. However, this repo above is the only one that made me able to make a desktop version of Raspbian read only. What I mean is that most of the tutorials help you make your headless server-only Raspbian become read only. However, if you have a Raspbian with the GUI, then this script is the only one that I was able to make work (not saying it is the only one in the world).