Refine search
protected void wrapStringOnPanel(String message, Container container) { GridBagConstraints c = getDefaultConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; // Insets() args are top, left, bottom, right c.insets = new Insets(0, 0, 0, 0); GridBagLayout gbLayout = (GridBagLayout) container.getLayout(); while (message.length() > 0) { int newLineIndex = message.indexOf('\n'); String line; if (newLineIndex >= 0) { line = message.substring(0, newLineIndex); message = message.substring(newLineIndex + 1); } else { line = message; message = ""; } Label label = new Label(line); label.setFont(DISPLAY_FONT); gbLayout.setConstraints(label, c); container.add(label); } }
public void addGridComponent(Component component) { GridLayout l = (GridLayout) getContentPane().getLayout(); // Make more sections if necessary int availableSections = l.getColumns() * l.getRows(); if (availableSections == getContentPane().getComponentCount()) { getContentPane().setLayout(new GridLayout(l.getColumns() + 1, l.getRows() + 1)); } getContentPane().add(component); validate(); }
for (int i = 0; i < 5; i++) { buttons[i] = new JButton(borderConstraints[i]); borderPanel.add(buttons[i], borderConstraints[i]); contentPane.add(borderPanel); for (int i = 5; i < 8; i++) { buttons[i] = new JButton(Integer.toString(i)); flowPanel.add(buttons[i]); contentPane.add(flowPanel); @Override public void actionPerformed(ActionEvent ae) { CardLayout cardLayout = (CardLayout) cardPanel.getLayout(); cardLayout.next(cardPanel);
protected void wrapStringOnPanel(String message, Container container) { GridBagConstraints c = getDefaultConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; // Insets() args are top, left, bottom, right c.insets = new Insets(0, 0, 0, 0); GridBagLayout gbLayout = (GridBagLayout) container.getLayout(); while (message.length() > 0) { int newLineIndex = message.indexOf('\n'); String line; if (newLineIndex >= 0) { line = message.substring(0, newLineIndex); message = message.substring(newLineIndex + 1); } else { line = message; message = ""; } Label label = new Label(line); label.setFont(DISPLAY_FONT); gbLayout.setConstraints(label, c); container.add(label); } }
this.setPreferredSize(new Dimension(320, 240)); this.setBackground(new Color(random.nextInt())); this.add(new JLabel(name)); CardPanel p = new CardPanel("Panel " + String.valueOf(i)); combo.addItem(p); cards.add(p, p.toString()); public void actionPerformed(ActionEvent e) { JComboBox jcb = (JComboBox) e.getSource(); CardLayout cl = (CardLayout) cards.getLayout(); cl.show(cards, jcb.getSelectedItem().toString()); control.add(combo); f.add(cards, BorderLayout.CENTER); f.add(control, BorderLayout.SOUTH);
this.setPreferredSize(new Dimension(320, 240)); this.setBackground(new Color(random.nextInt())); this.add(new JLabel(name)); for (int i = 1; i < 9; i++) { CardPanel p = new CardPanel("Panel " + String.valueOf(i)); cards.add(p, p.toString()); control.add(new JButton(new AbstractAction("\u22b2Prev") { CardLayout cl = (CardLayout) cards.getLayout(); cl.previous(cards); CardLayout cl = (CardLayout) cards.getLayout(); cl.next(cards);
/** * Adds a "middle" field component. Any component may be * used. The component will be stretched to take all of * the space between the label and the "last" field. All * "middle" fields in the layout will be the same width. */ public void addMiddleField(Component c, Container parent) { GridBagLayout gbl = (GridBagLayout) parent.getLayout(); gbl.setConstraints(c, middleConstraints); parent.add(c); }
/** * Adds a field component. Any component may be used. The * component will be stretched to take the remainder of * the current row. */ public void addLastField(Component c, Container parent) { GridBagLayout gbl = (GridBagLayout) parent.getLayout(); gbl.setConstraints(c, lastConstraints); parent.add(c); }
/** * Adds an arbitrary label component, starting a new row * if appropriate. The width of the component will be set * to the minimum width of the widest component on the * form. */ public void addLabel(Component c, Container parent) { GridBagLayout gbl = (GridBagLayout) parent.getLayout(); gbl.setConstraints(c, labelConstraints); parent.add(c); }
protected void add(Container container, Component component, GridBagConstraints constraints, int x, int y, int width, int height) { constraints.gridx = x; constraints.gridy = y; constraints.gridwidth = width; constraints.gridheight = height; LayoutManager layout = container.getLayout(); if (layout != null && layout instanceof GridBagLayout) { ((GridBagLayout)layout).setConstraints(component, constraints); } container.add(component); } }
private static void addComponent (Container container, Component component) { GridBagConstraints c = new GridBagConstraints(); c.gridx = c.gridy = GridBagConstraints.RELATIVE; c.gridheight = c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTHWEST; c.weightx = c.weighty = 1.0; ((GridBagLayout)container.getLayout()).setConstraints (component,c); container.add (component); }
private static void addComponent (Container container, Component component) { GridBagConstraints c = new GridBagConstraints(); c.gridx = c.gridy = GridBagConstraints.RELATIVE; c.gridheight = c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.NORTHWEST; c.weightx = c.weighty = 1.0; ((GridBagLayout)container.getLayout()).setConstraints (component,c); container.add (component); }
private void addGBRow(final Container container, final Component comp, final Component previous) { final GridBagLayout gb = (GridBagLayout) container.getLayout(); GridBagConstraints c = null; if (null == previous) { c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTHWEST; c.fill = GridBagConstraints.HORIZONTAL; c.gridy = 0; } else { c = gb.getConstraints(previous); c.gridy += 1; } gb.setConstraints(comp, c); container.add(comp); }
/** * Add the specified editor. No editor must exists for the specified name prior to this * call. The editor will be bring on top of the card layout (i.e. will become the visible * panel). * * @param name The editor name. Should be one of {@link #NUMBER}, {@link #KERNEL} and * similar constants. * @param editor The editor. * @param scroll {@code true} if the editor should be wrapped into a {@link JScrollPane} * prior its addition to the container. */ private void addEditor(final String name, Component editor, final boolean scroll) { if (editors.put(name, editor) != null) { throw new IllegalStateException(name); // Should not happen. } if (scroll) { editor = new JScrollPane(editor); } cards.add(editor, name); ((CardLayout) cards.getLayout()).show(cards, name); }
public static void main(String[] args) { JFrame f = new JFrame("a"); JToolBar bar = new JToolBar(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().setLayout(new FlowLayout()); System.out.println(f.getContentPane().getLayout().getClass().getName()); NavBox navBox = new NavBox(); navBox.setSize(500, 40); navBox.setMaximumSize(new Dimension(500, 20)); navBox.setMinimumSize(new Dimension(500, 20)); f.getContentPane().add(bar); bar.add(navBox); bar.add(new JButton("G")); f.setSize(300, 60); f.setVisible(true); }