List of usage examples for java.awt Container setLayout
public void setLayout(LayoutManager mgr)
From source file:AccessoryFileChooser.java
public AccessoryFileChooser() { super("Accessory Test Frame"); setSize(350, 200);// w w w.jav a 2 s . c o m setDefaultCloseOperation(EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); JButton accButton = new JButton("Accessory"); statusbar = new JLabel("Output of your selection will go here"); chooser = new JFileChooser(); AudioAccessory aa = new AudioAccessory(); chooser.setAccessory(aa); chooser.addPropertyChangeListener(aa); // to receive selection changes chooser.addActionListener(aa); // to receive approve/cancel button // events accButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int option = chooser.showOpenDialog(AccessoryFileChooser.this); if (option == JFileChooser.APPROVE_OPTION) { statusbar.setText("You chose " + ((chooser.getSelectedFile() != null) ? chooser.getSelectedFile().getName() : "nothing")); } else { statusbar.setText("You canceled."); } } }); c.add(accButton); c.add(statusbar); }
From source file:visolate.Main.java
public void init() { visolate = new Visolate(); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(visolate, "Center"); contentPane.setBackground(Color.WHITE); SwingUtilities.invokeLater(new Runnable() { public void run() { visolate.loadDemo();/* ww w . j a v a 2s. co m*/ } }); }
From source file:org.ut.biolab.medsavant.client.view.dialog.ProgressDialog.java
ProgressDialog(String title, String message, boolean cancellable) { super(DialogUtils.getFrontWindow(), title, Dialog.ModalityType.APPLICATION_MODAL); setResizable(false);/*from w ww .jav a2 s.c o m*/ Container p = getContentPane(); p.setLayout(new GridBagLayout()); JLabel messageLabel = new JLabel(message); bar = ViewUtil.getIndeterminateProgressBar(); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(15, 45, 3, 45); p.add(messageLabel, gbc); gbc.insets = new Insets(3, 45, cancellable ? 3 : 30, 45); p.add(bar, gbc); setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); }
From source file:UndoableToggleApp2.java
public UndoableToggleApp2() { JToggleButton tog = new JToggleButton("ToggleButton"); JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox"); JRadioButton radio = new JRadioButton("RadioButton"); SimpleListener sl = new SimpleListener(); tog.addActionListener(sl);/*from w ww.ja va 2 s.com*/ cb.addActionListener(sl); radio.addActionListener(sl); Box buttonBox = new Box(BoxLayout.Y_AXIS); buttonBox.add(tog); buttonBox.add(cb); buttonBox.add(radio); undoButton.setEnabled(false); redoButton.setEnabled(false); endButton.setEnabled(false); undoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.undo(); } catch (CannotUndoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); redoButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { try { edit.redo(); } catch (CannotRedoException ex) { ex.printStackTrace(); } finally { undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } } }); endButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { edit.end(); endButton.setEnabled(false); undoButton.setEnabled(edit.canUndo()); redoButton.setEnabled(edit.canRedo()); } }); Box undoRedoEndBox = new Box(BoxLayout.X_AXIS); undoRedoEndBox.add(Box.createGlue()); undoRedoEndBox.add(undoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(redoButton); undoRedoEndBox.add(Box.createHorizontalStrut(2)); undoRedoEndBox.add(endButton); undoRedoEndBox.add(Box.createGlue()); Container content = getContentPane(); content.setLayout(new BorderLayout()); content.add(buttonBox, BorderLayout.CENTER); content.add(undoRedoEndBox, BorderLayout.SOUTH); setSize(400, 150); }
From source file:CoordinatesDemo.java
private void buildUI(Container container) { container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS)); CoordinateArea coordinateArea = new CoordinateArea(this); container.add(coordinateArea);/*from w ww . ja v a 2 s. c o m*/ label = new JLabel(); resetLabel(); container.add(label); coordinateArea.setAlignmentX(Component.LEFT_ALIGNMENT); label.setAlignmentX(Component.LEFT_ALIGNMENT); // redundant }
From source file:StringDistance.java
public StringDistance(String[] strs) throws InlineJavaException { frame = new JFrame("StringDistance"); Container p = frame.getContentPane(); p.setLayout(new GridLayout(0, 2)); // The input fields, including labels: tf = new JTextField[2]; for (int i = 0; i < 2; i++) { p.add(new JLabel("String " + i + ":")); tf[i] = new JTextField(20); if ((strs != null) && (i < strs.length)) tf[i].setText(strs[i]);// www .j a v a 2s . c o m p.add(tf[i]); } // The output field, including label: p.add(new JLabel("Distance:")); dist = new JTextField(5); dist.setEditable(false); p.add(dist); // The main action button: go = new JButton("Compute distance"); go.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { dist.setText(Integer.toString(match(tf[0].getText(), tf[1].getText()))); } }); p.add(go); // To finish off: exit = new JButton("Exit"); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { frame.dispose(); System.exit(0); } }); p.add(exit); if ((strs != null) && (strs.length > 1)) dist.setText(Integer.toString(match(tf[0].getText(), tf[1].getText()))); frame.pack(); }
From source file:phex.gui.dialogs.LogBufferDialog.java
/** * // ww w . j ava2 s. co m */ private void prepareComponent() { CloseEventHandler closeEventHandler = new CloseEventHandler(); addWindowListener(closeEventHandler); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel contentPanel = new JPanel(); //JPanel contentPanel = new FormDebugPanel(); contentPane.add(contentPanel, BorderLayout.CENTER); CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("4dlu, fill:d:grow, 4dlu", // columns "p, p, 2dlu, fill:p:grow, 4dlu, p, 4dlu"); //row PanelBuilder contentPB = new PanelBuilder(layout, contentPanel); DialogBanner banner = new DialogBanner(Localizer.getString("LogBufferDialog_Log"), Localizer.getString("LogBufferDialog_DisplayLog")); contentPB.add(banner, cc.xywh(1, 1, 3, 1)); contentPB.add(new JSeparator(), cc.xywh(1, 2, 3, 1)); JTextArea logArea = new JTextArea(40, 100); logArea.setEditable(false); contentPB.add(new JScrollPane(logArea), cc.xy(2, 4)); JButton closeBtn = new JButton(Localizer.getString("Close")); closeBtn.addActionListener(closeEventHandler); contentPB.add(ButtonBarFactory.buildCloseBar(closeBtn), cc.xy(2, 6)); StringBuffer textBuffer = new StringBuffer(); Iterator iterator = logEntries.iterator(); while (iterator.hasNext()) { LogRecord record = (LogRecord) iterator.next(); textBuffer.append(dateFormat.format(new Date(record.getTimestamp()))).append("::") .append(record.getMessage()).append(SystemUtils.LINE_SEPARATOR); } logArea.setText(textBuffer.toString()); //logArea.setCaretPosition(0); pack(); setLocationRelativeTo(getParent()); }
From source file:com.db2eshop.gui.dialog.EditDialog.java
private void buildEditor() { this.getContentPane().removeAll(); Container container = this.getContentPane(); container.setLayout(new MigLayout("fill")); components = uiBinder.create(model); /*/* ww w . j a v a 2s .c om*/ * TODO * find workaround, this is a ugly hack */ // for (LabeledInput<?> labeledInput : components.values()) { // if(labeledInput instanceof EmbeddedEntityInput){ // ((EmbeddedEntityInput)labeledInput).getHashedJListEntries().put(Null.getInstance().toString(), Null.getInstance()); // JList jList = ((EmbeddedEntityInput)labeledInput).getjList(); // ((DefaultListModel)jList.getModel()).addElement(Null.getInstance()); // } // } for (LabeledForm<?> labeledInput : components.values()) { container.add(labeledInput, "wrap"); } this.repaint(); }
From source file:com.jcraft.weirdx.XRexec.java
public XRexec(String myName, int num) { try {/*from w w w.j av a2s . c o m*/ InetAddress local = null; if (myName != null && myName.length() > 0) { local = InetAddress.getByName(myName); } else { local = InetAddress.getLocalHost(); } display = local.getHostName() + ":" + num + ".0"; } catch (Exception e) { display = "localhost:" + num + ".0"; LOG.error(e); } JFrame jframe = new JFrame(); Container cpane = jframe.getContentPane(); cpane.setLayout(new GridLayout(0, 1)); JPanel jpanel = null; jpanel = new JPanel(); jpanel.setBorder(BorderFactory.createTitledBorder("Host")); jpanel.setLayout(new BorderLayout()); host.setText(""); host.setMinimumSize(new Dimension(50, 25)); host.setEditable(true); jpanel.add(host, "Center"); cpane.add(jpanel); jpanel = new JPanel(); jpanel.setBorder(BorderFactory.createTitledBorder("User")); jpanel.setLayout(new BorderLayout()); name.setText(""); name.setMinimumSize(new Dimension(50, 25)); name.setEditable(true); jpanel.add(name, "Center"); cpane.add(jpanel); jpanel = new JPanel(); jpanel.setBorder(BorderFactory.createTitledBorder("Password")); jpanel.setLayout(new BorderLayout()); passwd.setMinimumSize(new Dimension(50, 25)); passwd.setEditable(true); jpanel.add(passwd, "Center"); cpane.add(jpanel); jpanel = new JPanel(); jpanel.setBorder(BorderFactory.createTitledBorder("Command with Absolute Path")); jpanel.setLayout(new BorderLayout()); command.setText(""); command.setMinimumSize(new Dimension(50, 25)); command.setEditable(true); jpanel.add(command, "Center"); command.addActionListener(this); cpane.add(jpanel); jpanel = new JPanel(); jpanel.add(rexec, "Center"); rexec.addActionListener(this); cpane.add(jpanel); jframe.pack(); jframe.setVisible(true); }
From source file:com.diversityarrays.wizard.WizardRunner.java
public Window showRelativeTo(Component relativeTo) { RootPaneContainer rpc = ((RootPaneContainer) window); Container cp = rpc.getContentPane(); cp.setLayout(new BorderLayout()); cp.add(status, BorderLayout.NORTH); cp.add(this, BorderLayout.CENTER); window.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { cancel();/*from w w w.j a va2 s . co m*/ } }); status.setText("Active"); addWizardListener(wizardListener); window.pack(); Dimension d = window.getSize(); ++d.width; window.setSize(d); window.setLocationRelativeTo(relativeTo); window.setVisible(true); window.toFront(); return window; }