List of usage examples for javax.swing JPanel JPanel
public JPanel(boolean isDoubleBuffered)
JPanel
with FlowLayout
and the specified buffering strategy. From source file:Main.java
/** * Creates a JPanel containing the component hugging the left side * @param component the component to wrap * @return a JPanel containing the component hugging the left side *//*ww w .ja va 2s .c o m*/ public static JPanel hugWest(JComponent component) { final JPanel result = new JPanel(new BorderLayout()); result.add(component, BorderLayout.WEST); return result; }
From source file:Main.java
/** * Creates a JPanel containing the component hugging the bottom side * @param component the component to wrap * @return a JPanel containing the component hugging the bottom side *///from w w w . ja v a 2 s. c om public static JPanel hugSouth(JComponent component) { final JPanel result = new JPanel(new BorderLayout()); result.add(component, BorderLayout.SOUTH); return result; }
From source file:Main.java
/** * Creates a <code>JPanel</code> containing the given text placed in the * center as the only component./*from w w w.j a v a 2 s . co m*/ * @param text - the text to put on the panel * @return a JPanel containing only the given text */ public static JPanel makeTextPanel(String text) { JPanel panel = new JPanel(false); JLabel filler = new JLabel(text); filler.setHorizontalAlignment(SwingConstants.CENTER); panel.setLayout(new GridLayout(1, 1)); panel.add(filler); return panel; }
From source file:Main.java
static void createFrameAtLocation(Point p) { JFrame frame = new JFrame(); frame.setTitle("Test frame on two screens"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JTextArea textareaA = new JTextArea(24, 80); textareaA.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY, 1)); panel.add(textareaA, BorderLayout.CENTER); frame.setLocation(p);/*from ww w . ja v a2 s . c o m*/ frame.add(panel); frame.pack(); frame.setExtendedState(Frame.MAXIMIZED_BOTH); frame.setVisible(true); }
From source file:MainClass.java
public static JPanel demo1() { JPanel pan = new JPanel(new BorderLayout()); pan.setBorder(new TitledBorder("change format midstream")); MaskFormatter lowercase = null; try {/* w w w. ja v a2 s . c o m*/ lowercase = new MaskFormatter("LLLL"); } catch (ParseException pe) { } final JFormattedTextField field = new JFormattedTextField(lowercase); field.setValue("lower case"); pan.add(field, BorderLayout.CENTER); final JButton change = new JButton("change format"); JPanel changePanel = new JPanel(); changePanel.add(change); pan.add(changePanel, BorderLayout.SOUTH); change.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { field.commitEdit(); MaskFormatter uppercase = new MaskFormatter("UUUU"); DefaultFormatterFactory factory = new DefaultFormatterFactory(uppercase); field.setFormatterFactory(factory); change.setEnabled(false); } catch (ParseException pe) { } } }); return pan; }
From source file:Main.java
/** * Displays a message dialog with given information. *///from www.j a v a 2s. c o m public static void showInformationDialog(Component component, String message) { final JPanel panel = new JPanel(new BorderLayout(5, 5)); final JLabel messageLabel = new JLabel(message); messageLabel.setFont(new Font("Dialog", Font.BOLD, messageLabel.getFont().getSize())); panel.add(messageLabel, BorderLayout.CENTER); // Adjust stack trace dimensions final Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); screenDimension.setSize(screenDimension.getWidth() * 0.7, screenDimension.getHeight() * 0.7); final Dimension maxStackTraceDimension = new Dimension(500, 500); maxStackTraceDimension.setSize(Math.min(maxStackTraceDimension.getWidth(), screenDimension.getWidth()), Math.min(maxStackTraceDimension.getHeight(), screenDimension.getHeight())); JOptionPane.showMessageDialog(component, panel, "Information", JOptionPane.INFORMATION_MESSAGE); }
From source file:Main.java
public static JPanel createFlow(final int align, final int gap, final Object... components) { final JPanel jp = new JPanel(new FlowLayout(align, gap, gap)); jp.setBorder(BorderFactory.createEmptyBorder()); for (final Object component : components) { if (component instanceof Component) { initComponentHeight((Component) component); jp.add((Component) component); } else if (component instanceof Number) { jp.add(Box.createHorizontalStrut(((Number) component).intValue())); }/*w w w. j a v a 2 s . co m*/ } return jp; }
From source file:FactoryDemo.java
public static JPanel demo1() { // Demo 1: field with different formats with focus and without JPanel pan = new JPanel(new BorderLayout()); pan.setBorder(new TitledBorder("Demo 1: format toggles with focus")); MaskFormatter withFocus = null, withoutFocus = null; try {//www. j av a 2 s . c om withFocus = new MaskFormatter("LLLL"); withoutFocus = new MaskFormatter("UUUU"); } catch (ParseException pe) { } DefaultFormatterFactory factory = new DefaultFormatterFactory(withoutFocus, null, withFocus); JFormattedTextField field = new JFormattedTextField(factory); field.setValue("Four"); pan.add(field, BorderLayout.CENTER); return pan; }
From source file:Main.java
/** * Put a series of {@link JComponent}s in a {@link JPanel} which has a {@link FlowLayout}. * * @param position//w w w.j a v a 2s.com * Position of components, left, right, or center justified (for example, {@link * java.awt.FlowLayout#CENTER)} * @param opaque * True if the returned JPanel should be opaque * @param firstComponent * The first {@link JComponent} to add * @param remainingComponents * The rest of the {@link JComponent}s to add * @return A {@link JPanel} with a {@link FlowLayout} which contains all the passed {@link JComponent}s. */ public static JPanel putComponentsInFlowLayoutPanel(int position, boolean opaque, JComponent firstComponent, JComponent... remainingComponents) { JPanel flowLayoutPanel = new JPanel(new FlowLayout(position)); flowLayoutPanel.setOpaque(opaque); flowLayoutPanel.add(firstComponent); for (JComponent component : remainingComponents) { flowLayoutPanel.add(component); } return flowLayoutPanel; }
From source file:Main.java
public Main() { JPanel bigPanel = new JPanel(new GridBagLayout()); JPanel panel_a = new JPanel(); JButton btnA = new JButton("button a"); panel_a.add(btnA);/* ww w.j av a 2 s . c o m*/ JPanel panel_b = new JPanel(); JButton btnB = new JButton("button b"); panel_b.add(btnB); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; bigPanel.add(panel_a, c); bigPanel.add(panel_b, c); c.weighty = 1.0; bigPanel.add(new JPanel(), c); this.add(bigPanel); }