I need to remove maximize and minimize buttons from jframe to reduce width further. Please suggest how can i do that.
views:
403answers:
2
+2
A:
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Dlg extends JDialog {
public Dlg(JFrame frame, String str) {
super(frame, str);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
}
});
}
public static void main(String[] args) {
try {
Dlg frame = new Dlg(new JFrame(), "No min max buttons");
JPanel panel = new JPanel();
panel.setSize(200, 200);
JLabel lbl = new JLabel("blah blah");
panel.add(lbl);
frame.add(panel);
frame.setSize(400, 400);
frame.setVisible(true);
} catch (IllegalArgumentException e) {
System.exit(0);
}
}
}
stacker
2010-04-19 06:01:06
The `setResizable` method does not remove any buttons from the title bar. It only disables the maximize button.
Matthew T. Staebler
2010-04-19 06:27:50
@Aeth - thanks removed that, the Dialog example works (tested)
stacker
2010-04-19 06:55:47
+2
A:
Here's a related example using setUndecorated()
to disable the frame decorations.
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class FrameTest implements Runnable {
public static void main(String[] args) {
EventQueue.invokeLater(new FrameTest());
}
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setUndecorated(true);
JPanel panel = new JPanel();
panel.add(new JLabel("Stackoverflow!"));
panel.add(new JButton(new AbstractAction("Close") {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}));
f.add(panel);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
trashgod
2010-08-20 20:31:55