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)
Take a look at this implementation: http://www.java2s.com/Code/Java/Swing-Components/InvisibleNodeTreeExample.htm It creates subclasses of DefaultMutableNode adding a “isVisible” property rather then actually removing/adding nodes from the TreeModel. Pretty sweet I think, and it solved my filtering problem neatly.
It’s not two competing mechanisms – a JPanel is a Container (just look at the class hierarchy at the top of the JPanel javadocs). JFrame.getContentPane() just returns a Container to place the Components that you want to display in the JFrame. Internally, it’s using a JPanel (by default – you can change this by calling … Read more
Yes, it is possible using JOptionPane.showOptionDialog(). Something like this: JPanel panel = new JPanel(); JLabel label = new JLabel(“Enter a password:”); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass); String[] options = new String[]{“OK”, “Cancel”}; int option = JOptionPane.showOptionDialog(null, panel, “The title”, JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if(option == 0) // pressing OK button { char[] … Read more
Calling setCaretPosition(0) on your text component will cause it to scroll to the top.
At run-time, we can use Font.canDisplayUpTo(String) to determine which of the installed fonts can display a given text. Logical fonts such as Font.SANS_SERIF and Font.SERIF typically are made of of other fonts and can cover vast ranges of different scripts. Here is an example using the given text, with the results seen on this machine. … Read more
Here is an example the fades the background as you move from component to component: import java.awt.*; import java.awt.event.*; import java.util.Hashtable; import java.util.ArrayList; import javax.swing.*; public class Fader { // background color when component has focus private Color fadeColor; // steps to fade from original background to fade background private int steps; // apply transition … Read more
Something like this might work for PacMan images. It uses a Java 2D based Shape instance to represent the form, and an AffineTransform to produce the different orientations. import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.awt.image.BufferedImage; import javax.swing.*; import java.io.*; import javax.imageio.ImageIO; class PacManShape { private double size; private double rotation; final int maxSize = … Read more
However, I struggle with arrays and I am sure that I am not doing it correctly. I wouldn’t use Arrays. Instead, have a Ball object manage its own state. Then you can have different color, speed, size etc for each Ball. Then when the Timer fires you just calculate the new position and repaint the … Read more
Don’t use setBounds() to set the size and location of a component. Let the layout manager do its job. That is if fact what is happening. A JPanel uses a FlowLayout, so the components are being positioned based on the rules of the FlowLayout. You can change the FlowLayout to align components to the left … Read more