'How to maximize undecorated java swing screen?
I would like to know how do I make the screen maximized in the undecorated Jframe, because with the undecorated false it maximizes normally, but with the undecorated true the jframe looks like this.
private void jlMaximizarMenuMouseClicked(java.awt.event.MouseEvent evt) {
if (this.getExtendedState() != Menu.MAXIMIZED_BOTH)
{
this.setExtendedState(Menu.MAXIMIZED_BOTH);
}
else
{
this.setExtendedState(Menu.NORMAL);
}
}
Solution 1:[1]
This simple example works perfectly fine, your issue is some where else in code you are not sharing. I'm guessing you're using a transparent window, which suggests that either you're not using one or more appropriate layouts or you're otherwise screwing with the layout information, in any case, without a minimal reproducible example, there's not much more we can do to help you.
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.add(new TestPane());
frame.setUndecorated(true);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class TestPane extends JPanel {
public TestPane() {
JButton normal = new JButton("Normal");
JButton maximized = new JButton("Maximixed");
JButton minimized = new JButton("Minimized");
add(normal);
add(maximized);
add(minimized);
normal.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
((JFrame)SwingUtilities.windowForComponent(TestPane.this)).setExtendedState(JFrame.NORMAL);
}
});
maximized.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
((JFrame)SwingUtilities.windowForComponent(TestPane.this)).setExtendedState(JFrame.MAXIMIZED_BOTH);
}
});
minimized.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
((JFrame)SwingUtilities.windowForComponent(TestPane.this)).setExtendedState(JFrame.ICONIFIED);
}
});
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
