Possible Duplicate:
JButton minimizing a window(JFrame)
I removed the JFrame's close/minimize buttons, and I want to add my own buttons, for close, it can work by using .dispose();, but what should I use to minimize the JFrame if I click on a JButton?
I think .setVisible(false); will hide it completely, and I won't have anything to click on, in the TaskBar to get the JFrame back.
Just use .setState(Frame.ICONIFIED)
Working Example:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FrameTest {
public static void main(String args[]) throws Exception {
final JFrame frame = new JFrame();
frame.setUndecorated(true);
JButton button = new JButton("Minimize");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setState(Frame.ICONIFIED);
}
});
frame.add(button);
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With