import java.awt.Dimension; import javax.swing.JFrame; public class JFrameExample { public static void main(String[] args) { JFrame frame = new JFrame("Hello World"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setMinimumSize(new Dimension(100, 100)); frame.setVisible(true); } }
public class JavaGui extends javax.swing.JFrame { public JavaGui() { setMinimumSize(1154, 753); // Make sure you do setMinimumSize() instead of setSize() when using pack() so that the JFrame does not shrink to 0 size setLayout(null); add(panelLeft); add(panelRight); pack(); } // Next is main method
setMinimumSize(new Dimension(400, 400)); setVisible(true);
final JFrame frame = new JFrame("Nested Layout Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); plafComponents.add(plafChooser); plafComponents.add(pack); SwingUtilities.updateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame.setMinimumSize(frame.getSize()); gui.add(plafComponents, BorderLayout.NORTH); frame.pack(); frame.setMinimumSize(frame.getSize()); } catch(Throwable ignoreAndContinue) { frame.setVisible(true);
import java.awt.*; import java.awt.Dialog.ModalityType; import javax.swing.*; public class SSCCE { public static void main(String[] args) { JDialog dlg = new JDialog(null, ModalityType.APPLICATION_MODAL); dlg.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel pnl = new JPanel(new BorderLayout()); pnl.add(new JLabel("As big as needed"), BorderLayout.CENTER); //pnl.setMinimumSize(new Dimension(300,300)); dlg.add(pnl); System.out.println("Dialog minimum size: " + dlg.getMinimumSize()); dlg.pack(); // make the dialog as large as needed to display content // Minimum size is not enforced by the OS without this call dlg.setMinimumSize(dlg.getPreferredSize()); System.out.println("Dialog minimum size: " + dlg.getMinimumSize()); dlg.setVisible(true); } }
JPanel fontNameCol = new JPanel(new GridLayout(0, 1, 2, 2)); JPanel fontExampleCol = new JPanel(new GridLayout(0, 1, 2, 2)); fontTable.add(fontNameCol, BorderLayout.WEST); fontTable.add(fontExampleCol, BorderLayout.CENTER); for (int ii = 0; ii < fonts.length; ii++) { fontNameCol.add(new JLabel(fonts[ii])); fontExampleCol.add(getExampleOfFont(fonts[ii])); p.add(tabPane, BorderLayout.CENTER); p.setPreferredSize(new Dimension(400, 400)); JFrame f = new JFrame("Properties"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.getContentPane().add(p, BorderLayout.CENTER); f.pack(); f.setMinimumSize(f.getPreferredSize()); f.setSize(600, 500); f.setLocationRelativeTo(null); f.setVisible(true);
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); p.add(f); frame.add(p); frame.pack(); frame.setVisible(true); lastFocusableIndex = 0; sl.setFocused(false); autoSuggestionPopUpWindow.setVisible(false); setFocusToTextField(); autoSuggestionPopUpWindow.setVisible(false); setFocusToTextField(); suggestionsPanel.add(suggestionLabel); autoSuggestionPopUpWindow.getContentPane().add(suggestionsPanel); autoSuggestionPopUpWindow.setMinimumSize(new Dimension(textField.getWidth(), 30)); autoSuggestionPopUpWindow.setSize(tW, tH); autoSuggestionPopUpWindow.setVisible(true); autoSuggestionPopUpWindow.setMinimumSize(new Dimension(textField.getWidth(), 30)); autoSuggestionPopUpWindow.revalidate(); autoSuggestionPopUpWindow.repaint();
JToolBar tools = new JToolBar(); tools.setFloatable(false); gui.add(tools, BorderLayout.PAGE_START); tools.add(new JButton("New")); // TODO - add functionality! tools.add(new JButton("Save")); // TODO - add functionality! tools.add(new JButton("Restore")); // TODO - add functionality! tools.addSeparator(); new ChessBoardWithColumnsAndRows(); JFrame f = new JFrame("ChessChamp"); f.add(cb.getGui()); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLocationByPlatform(true); f.pack(); f.setMinimumSize(f.getSize()); f.setVisible(true);
ui.add(text, BorderLayout.PAGE_START); io = new JTextField(15); Font font = io.getFont(); io.setHorizontalAlignment(SwingConstants.TRAILING); io.setFocusable(false); text.add(io); ui.add(buttons, BorderLayout.CENTER); String[] keyValues = { "7", "8", "9", "/", public void run() { ScriptEngineCalculator sc = new ScriptEngineCalculator(); JFrame f = new JFrame("Calculet"); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setContentPane(sc.getUI()); f.pack(); f.setMinimumSize(f.getSize()); f.setLocationByPlatform(true); f.setVisible(true);
Box box = new Box(BoxLayout.Y_AXIS); box.setAlignmentX(JComponent.CENTER_ALIGNMENT); box.add(Box.createVerticalGlue()); box.add(new CustomComponents12()); box.add(Box.createVerticalGlue()); add(box); pack(); setTitle("Custom Component Test / BoxLayout"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setMaximumSize(getMinimumSize()); setMinimumSize(getMinimumSize()); setPreferredSize(getPreferredSize()); setLocation(150, 150); setVisible(true);
getContentPane().add(bp); validate(); SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame f = new JFrame("Beeper"); f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); BeeperPanel BeeperPanel = new BeeperPanel(); f.setContentPane(BeeperPanel); f.pack(); f.setMinimumSize( f.getSize() ); f.setLocationByPlatform(true); f.setVisible(true); JPanel pSampleRate = new JPanel(new BorderLayout()); pSampleRate.setBorder(new TitledBorder("Sample Rate")); pSampleRate.add( sampleRate ); sampleRate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { options.add( pSampleRate );
import javax.swing.JFrame; import java.awt.Dimension; public class Ex extends JFrame { public static void main(String[] args) { JFrame frame = new JFrame("YOU CAN'T SHRINK ME COMPLETELY!"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setMinimumSize(new Dimension(100, 100)); frame.setVisible(true); } }
import java.awt.*; import javax.swing.*; public class Example { public static void main(String args[]) { JFrame frame = new JFrame(); JMenuBar menubar = new JMenuBar(); JLabel label = new JLabel("Hello World"); menubar.setLayout(new BorderLayout()); menubar.add(label, BorderLayout.EAST); frame.setLayout(new BorderLayout()); frame.add(menubar, BorderLayout.PAGE_START); frame.setMinimumSize(new Dimension(200, 100)); frame.setVisible(true); } }
private JFrame frame = new JFrame(); panel.add(btn); frame.add(tabbedPane, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setMinimumSize(new Dimension(300, 300)); frame.setVisible(true);
import javax.swing.JFrame; import java.awt.Insets; public class JFrameInsets extends JFrame { @Override public Insets getInsets() { return new Insets(10, 10, 10, 10); } private JFrameInsets() { super("Insets of 10"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); setMinimumSize(getSize()); setVisible(true); } public static void main(String[] args) { new JFrameInsets(); } }
Runnable r = new Runnable() { public void run() { JFrame jf=new JFrame("This is JFrame"); JPanel h=new JPanel(); h.add(new JButton("Button")); h.add(new JLabel("this is JLabel")); h.setBackground(Color.RED); jf.add(h); jf.getContentPane().setBackground(Color.BLACK); jf.setLayout(new FlowLayout()); jf.setVisible(true); jf.pack(); jf.setMinimumSize(jf.getSize()); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
super(title); JLabel lab = new JLabel("Label"); this.getContentPane().add(lab); this.setMinimumSize(new Dimension(200, 200)); this.pack(); this.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@Override public void run() { JFrame f = new JFrame("Button GUI"); JButton b = new JButton("CLICK"); p.add(b); f.add(p); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLocationByPlatform(true); f.pack(); f.setMinimumSize(f.getSize()); f.setVisible(true);
private JFrame frame = new JFrame(); frame.add(ui); ui.setBorder(new LineBorder(Color.CYAN, 3)); toolPanel.setBorder(new LineBorder(Color.ORANGE, 3)); ui.add(toolPanel, BorderLayout.PAGE_START); for (int i = 0; i < 3; i++) { toolPanel.add(new JButton("Button " + i)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); // pack will make it as small as it can be. frame.setMinimumSize(frame.getSize()); // nice tweak.. frame.setVisible(true);
JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new MyPanel()); frame.pack(); frame.setMinimumSize(frame.getPreferredSize()); frame.setVisible(true); gbc.weightx = 1; gbc.insets = new Insets(10, 10, 10, 10); north.add(labelD, gbc); south.add(labelA, gbc); gbc.gridy = 1; south.add(labelB, gbc);