Here is a sketch I made to try and remove buttons.
import g4p_controls.*;
import javax.swing.*;
import java.awt.*;
JFrame frame;
void setup() {
size(200, 200);
// Get frame for a GWindow using JAVA2D
GWindow window = GWindow.getWindow(this, "Second Window", 20, 20, 320, 240, JAVA2D);
frame = (JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas)
window.getSurface().getNative()).getFrame();
//remove buttons
JFrame frame;
frame = (JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas)
window.getSurface().getNative()).getFrame();
removeButtonsFromWindow(frame);
//frame.setUndecorated(true);
}
//remove buttons from JFrame
void removeButtonsFromWindow(Component comp) {
println(comp);
if (comp instanceof Button) {
int todo; //TODO only remove the exit button.
comp.getParent().remove(comp);
}
if (comp instanceof Container) {
Component[] comps = ((Container) comp).getComponents();
for (int i = 0; i < comps.length; i++) {
removeButtonsFromWindow(comps[i]);
}
}
}
and here is the output:
javax.swing.JFrame[frame0,20,20,326x268,layout=java.awt.BorderLayout,title=GWindowAWT,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,3,25,320x240,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
javax.swing.JRootPane[,3,25,320x240,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=]
javax.swing.JPanel[null.glassPane,0,0,320x240,hidden,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777217,maximumSize=,minimumSize=,preferredSize=]
javax.swing.JLayeredPane[null.layeredPane,0,0,320x240,alignmentX=0.0,alignmentY=0.0,border=,flags=0,maximumSize=,minimumSize=,preferredSize=,optimizedDrawingPossible=true]
javax.swing.JPanel[null.contentPane,0,0,320x240,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
processing.awt.PSurfaceAWT$SmoothCanvas[canvas0,0,0,320x240]
The recursive method for reaching all of the components is not finding the buttons on the window.
I also tried to set the window to be undecorated and this was the output error I was given:
IllegalComponentStateException: The frame is displayable.
Do you know why the buttons aren’t being found or why setUndecorated(true) isn’t working as expected?
The post that I am basing the recursive function to find the buttons off of is from 12 years ago. I suppose the structure of the swing components could be different now and isn’t allowing for a deeper recursive search to be made.