How to minimize a JFrame window from Java?
minimize with frame.setState(Frame.ICONIFIED) restore with frame.setState(Frame.NORMAL)
minimize with frame.setState(Frame.ICONIFIED) restore with frame.setState(Frame.NORMAL)
Use setLocationRelativeTo(null) This method has a special effect when you pass it a null. According to the Javadoc: If the component is null, or the GraphicsConfiguration associated with this component is null, the window is placed in the center of the screen. This should be done after setting the size or calling pack(), but before … Read more
You have 2 choices. You can change the layout of your frame: JFrame frame; frame.setLayout(new FlowLayout()); Now, if you add more than one box, it will show up on the frame. The other option is to do what you said you tried. (Adding a panel to the frame) JPanel pane = new JPanel(); frame.add(pane); (add … Read more
You can check out mr Rob Camick’s ComponentResizer class. Pretty simple and straight forward to use. Just instantiate the ComponentResizer and register the frame with something like: JFrame frame = new JFrame(); ComponentResizer cr = new ComponentResizer(); cr.registerComponent(frame); cr.setSnapSize(new Dimension(10, 10)); cr.setMaximumSize(new Dimension(…)); cr.setMinimumSize(new Dimension(…)); Here’s a complete example of using the class import java.awt.*; … Read more
Try this: package com.sandbox; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.WindowConstants; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; public class SwingSandbox { public static void main(String[] args) throws IOException { JFrame frame = buildFrame(); final BufferedImage image = ImageIO.read(new File(“C:\\Projects\\MavenSandbox\\src\\main\\resources\\img.jpg”)); JPanel pane = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); … Read more
The title bar can be removed by calling setUndecorated(true) on the Frame or JFrame instance, i.e. by setting the “undecorated” property to true. This removes both the title bar and the surrounding frame. Here’s the required code for the question: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Already there frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setUndecorated(true); // <– the title bar is removed here On … Read more
SwingWorker supports PropertyChange events, that is, you can listener to when the SwingWorker changes state or updates it’s progress…yes, SwingWorker even supports progress notification, for example This means you could set up a PropertyChangeListener to monitor changes to the progress and state properties and take appropriate actions… A worker that simple sets progress updates… public … Read more
This is a simple example for adding the background image in a JFrame: import javax.swing.*; import java.awt.*; import java.awt.event.*; class BackgroundImageJFrame extends JFrame { JButton b1; JLabel l1; public BackgroundImageJFrame() { setTitle(“Background Color for JFrame”); setSize(400,400); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); /* One way —————– setLayout(new BorderLayout()); JLabel background=new JLabel(new ImageIcon(“C:\\Users\\Computer\\Downloads\\colorful design.png”)); add(background); background.setLayout(new FlowLayout()); l1=new JLabel(“Here … Read more
import java.awt.*; import java.awt.event.*; import javax.swing.JFrame; import javax.swing.UIManager; /** * * @author Mohammad Faisal * ermohammadfaisal.blogspot.com * facebook.com/m.faisal6621 * */ public class HideToSystemTray extends JFrame{ TrayIcon trayIcon; SystemTray tray; HideToSystemTray(){ super(“SystemTray test”); System.out.println(“creating instance”); try{ System.out.println(“setting look and feel”); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){ System.out.println(“Unable to set LookAndFeel”); } if(SystemTray.isSupported()){ System.out.println(“system tray supported”); tray=SystemTray.getSystemTray(); Image image=Toolkit.getDefaultToolkit().getImage(“/media/faisal/DukeImg/Duke256.png”); ActionListener … Read more
You can see an example in Substance look-and-feel (mirrored source). Search the code for SubstanceRootPaneUI and SubstanceTitlePane. The implementation depends on other classes in Substance, and will not be easy to reuse outside the specific library – nor is it meant to.