Can not restore down a maximized window using the JAVA2D renderer
Hello Nick,
first of all I have to say that this issue is not fully UiBooster related. But your library inspired me to use the FlatLaf by myself. In the end it doesn't matter, because the issue is the same. In my Processing 3 application i use some child Applets. All of them using the JAVA2D renderer and are resizable. The parent process does the same. So far so good. Everything works fine. But when i add an UiBooster instance or set the FlatLaf by myself the windows are only maximizable. There is no way back to the size they had before. getExtendedState() reports always a 0 for NORMAL but not MAXIMIZED_BOOTH as it should.
Here comes a little example . Your UiBooster library must be installed or flatlaf-2.1.jar must be in \sketchfolder\code. A mouse click in one of the windows toggles between FlatLightLaf and FlatDarculaLaf.
import com.formdev.flatlaf.FlatDarculaLaf;
import com.formdev.flatlaf.FlatLightLaf;
import javax.swing.*;
import javax.swing.UIManager;
import processing.awt.PSurfaceAWT;
TestWindow testWindow;
FlatLaf laf;
static JFrame parentFrame;
static JFrame childFrame;
static boolean darkTheme = false;
void settings() {
laf = new FlatLaf();
size(400, 400, JAVA2D);
}
void setup() {
surface.setTitle("Parent");
surface.setResizable(true);
PSurfaceAWT surf = (PSurfaceAWT) getSurface();
PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas) surf.getNative();
parentFrame = (JFrame) canvas.getFrame();
testWindow = new TestWindow();
FlatLaf.toggleTheme();
}
void mouseClicked() {
FlatLaf.toggleTheme();
}
void draw() {
background(0);
}
class TestWindow extends PApplet {
public TestWindow () {
super();
PApplet.runSketch(new String[]{this.getClass().getName()}, this);
}
void settings() {
size(400, 200, JAVA2D);
}
void setup() {
surface.setTitle("Child");
surface.setResizable(true);
PSurfaceAWT surf = (PSurfaceAWT) getSurface();
PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas) surf.getNative();
childFrame = (JFrame) canvas.getFrame();
}
void mouseClicked() {
FlatLaf.toggleTheme();
}
void draw() {
background(255);
}
} // TestWindow
static class FlatLaf {
public FlatLaf() {
FlatDarculaLaf.setup();
FlatLightLaf.setup();
}
public static void setLookAndFeel() {
println();
try {
if (darkTheme == false) {
UIManager.setLookAndFeel(new FlatLightLaf());
System.err.println("Set FlatLightLaf...");
}
else {
UIManager.setLookAndFeel(new FlatDarculaLaf());
System.err.println("Set FlatDarculaLaf...");
}
} catch (Exception ee) {
System.err.println("Could not set Laf!");
ee.printStackTrace();
}
}
public static void updateUI(final JFrame jframe) {
System.err.println("Updating... " + jframe);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
SwingUtilities.updateComponentTreeUI(jframe);
} catch(Exception e) {
System.err.println(e);
System.err.println("Could not update the UI tree!");
e.printStackTrace();
}
}
});
}
public static void toggleTheme() {
darkTheme = !darkTheme;
setLookAndFeel();
updateUI(parentFrame);
updateUI(childFrame);
}
} // FlatLaf
So what do you think? Is it a Processing problem or the wrong use of the FlatLaf and the UI Manager?
Best Martin
Hi Martin,
thank you for your detailed issue. Your code snippets produces the same issue for me. Typically the compoents of UiBooster are build with JDialogs (from swing) which doesn't use the window maximization mode, thus I don't reallized this issue.
I tried the following code in my IDE and if works fine.
UIManager.setLookAndFeel(new FlatDarculaLaf());
final JFrame jFrame = new JFrame();
jFrame.add(new JLabel("test"));
jFrame.setSize(300, 300);
jFrame.setVisible(true);
After that I added the same as Processing sketch and it works as expected:
import com.formdev.flatlaf.FlatDarculaLaf;
import javax.swing.*;
void setup() {
try {
UIManager.setLookAndFeel(new FlatDarculaLaf());
} catch(Exception e) {
e.printStackTrace();
}
final JFrame jFrame = new JFrame();
jFrame.add(new JLabel("test"));
jFrame.setSize(300, 300);
jFrame.setVisible(true);
}
I think the issue could be in your code snippet or is a results of the very special way you use Processing 😊
Hello Nick,
thank you for your quick reply. My goal is to apply the FlatLaf to the Processing surface and to all of the later added child Applets. But this leads to the described issue. Adding new JFrames works of course, but then i have to add each Processing canvas (main and childs) to the JFrames by myself using JPanels because i want to have Processings output there. But it is like it is. If this is the only way for now i will do it ;)
``