List of usage examples for javax.swing Box createHorizontalGlue
public static Component createHorizontalGlue()
From source file:Main.java
public Main() { super("Demostrating BoxLayout"); final int SIZE = 3; Container c = getContentPane(); c.setLayout(new BorderLayout(30, 30)); Box boxes[] = new Box[4]; boxes[0] = Box.createHorizontalBox(); boxes[1] = Box.createVerticalBox(); boxes[2] = Box.createHorizontalBox(); boxes[3] = Box.createVerticalBox(); for (int i = 0; i < SIZE; i++) boxes[0].add(new JButton("boxes[0]: " + i)); for (int i = 0; i < SIZE; i++) { boxes[1].add(Box.createVerticalStrut(25)); boxes[1].add(new JButton("boxes[1]: " + i)); }/*from w ww.java 2 s. c o m*/ for (int i = 0; i < SIZE; i++) { boxes[2].add(Box.createHorizontalGlue()); boxes[2].add(new JButton("boxes[2]: " + i)); } for (int i = 0; i < SIZE; i++) { boxes[3].add(Box.createRigidArea(new Dimension(12, 8))); boxes[3].add(new JButton("boxes[3]: " + i)); } JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); for (int i = 0; i < SIZE; i++) { panel.add(Box.createGlue()); panel.add(new JButton("panel: " + i)); } c.add(boxes[0], BorderLayout.NORTH); c.add(boxes[1], BorderLayout.EAST); c.add(boxes[2], BorderLayout.SOUTH); c.add(boxes[3], BorderLayout.WEST); c.add(panel, BorderLayout.CENTER); setSize(350, 300); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
From source file:RasterDemo.java
public RasterDemo() { super();/*from w w w. j av a2 s . c o m*/ Container container = getContentPane(); displayPanel = new RasterPanel(); container.add(displayPanel); Box box = Box.createHorizontalBox(); flipButton = new JToggleButton("Flip the Image"); flipButton.addActionListener(new ButtonListener()); box.add(Box.createHorizontalGlue()); box.add(flipButton); box.add(Box.createHorizontalGlue()); container.add(box, BorderLayout.SOUTH); addWindowListener(new WindowEventHandler()); setSize(450, 400); show(); }
From source file:CommonLayouts.java
public CommonLayouts() { super("Common Layout Managers"); setSize(500, 380);/* ww w . ja va 2s . c om*/ JPanel desktop = new JPanel(); getContentPane().add(desktop); JPanel fr1 = new JPanel(); fr1.setBorder(new TitledBorder("FlowLayout")); fr1.setLayout(new FlowLayout()); fr1.add(new JButton("1")); fr1.add(new JButton("2")); fr1.add(new JButton("3")); fr1.add(new JButton("4")); desktop.add(fr1, 0); JPanel fr2 = new JPanel(); fr2.setBorder(new TitledBorder("GridLayout")); fr2.setLayout(new GridLayout(2, 2)); fr2.add(new JButton("1")); fr2.add(new JButton("2")); fr2.add(new JButton("3")); fr2.add(new JButton("4")); desktop.add(fr2, 0); JPanel fr3 = new JPanel(); fr3.setBorder(new TitledBorder("BorderLayout")); fr3.add(new JButton("1"), BorderLayout.NORTH); fr3.add(new JButton("2"), BorderLayout.EAST); fr3.add(new JButton("3"), BorderLayout.SOUTH); fr3.add(new JButton("4"), BorderLayout.WEST); desktop.add(fr3, 0); JPanel fr4 = new JPanel(); fr4.setBorder(new TitledBorder("BoxLayout - X")); fr4.setLayout(new BoxLayout(fr4, BoxLayout.X_AXIS)); fr4.add(new JButton("1")); fr4.add(Box.createHorizontalStrut(12)); fr4.add(new JButton("2")); fr4.add(Box.createGlue()); fr4.add(new JButton("3")); fr4.add(Box.createHorizontalGlue()); fr4.add(new JButton("4")); desktop.add(fr4, 0); JPanel fr5 = new JPanel(); fr5.setBorder(new TitledBorder("BoxLayout - Y")); fr5.setLayout(new BoxLayout(fr5, BoxLayout.Y_AXIS)); fr5.add(new JButton("1")); fr5.add(Box.createVerticalStrut(10)); fr5.add(new JButton("2")); fr5.add(Box.createGlue()); fr5.add(new JButton("3")); fr5.add(Box.createVerticalGlue()); fr5.add(new JButton("4")); desktop.add(fr5, 0); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:ec.display.chart.StatisticsChartPaneTab.java
/** * This method initializes jPanel //from w ww .jav a2 s.c o m * * @return javax.swing.JPanel */ private JPanel getJPanel() { if (jPanel == null) { jPanel = new JPanel(); jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.X_AXIS)); jPanel.add(Box.createHorizontalGlue()); jPanel.add(getPrintButton(), null); jPanel.add(getCloseButton(), null); } return jPanel; }
From source file:gate.termraider.gui.HyponymyDebugger.java
private void makeControlPanel() { goButton = new JButton("generate debugging table"); goButton.setToolTipText("This may take some time!"); goButton.addActionListener(new HDGoButtonActionListener(this)); controlPanel = new JPanel(); controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.X_AXIS)); controlPanel.add(Box.createHorizontalGlue()); controlPanel.add(goButton);//from w w w. j a va 2 s .c om controlPanel.add(Box.createHorizontalGlue()); }
From source file:com.l2jfree.config.gui.Configurator.java
public Configurator(ConfigClassInfo configClassInfo) { _configClassInfo = configClassInfo;/*from w ww. j av a 2 s . c o m*/ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); { final JMenuBar jMenuBar = new JMenuBar(); { jMenuBar.add(getLoadJButton()); } { jMenuBar.add(getRefreshJButton()); } { jMenuBar.add(Box.createHorizontalGlue()); } { jMenuBar.add(getSaveJButton()); } { jMenuBar.add(getStoreJButton()); } setJMenuBar(jMenuBar); } { final JPanel jPanel = new JPanel(); jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); { for (ConfigFieldInfo info : _configClassInfo.getConfigFieldInfos()) { final ConfigFieldInfoView view = new ConfigFieldInfoView(info); // LOW implement jPanel.add(view); } } add(new JScrollPane(jPanel)); } pack(); setSize(600, 400); setLocationByPlatform(true); setVisible(true); }
From source file:uk.ac.ebi.demo.picr.swing.PICRBLASTDemo.java
public PICRBLASTDemo() { //set general layout setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); add(Box.createVerticalStrut(5)); //create components JPanel row1 = new JPanel(); row1.setLayout(new BoxLayout(row1, BoxLayout.X_AXIS)); row1.add(Box.createHorizontalStrut(5)); row1.setBorder(BorderFactory.createTitledBorder("")); row1.add(new JLabel("Fragment:")); row1.add(Box.createHorizontalStrut(10)); final JTextArea sequenceArea = new JTextArea(5, 40); sequenceArea.setMaximumSize(sequenceArea.getPreferredSize()); row1.add(Box.createHorizontalStrut(10)); row1.add(sequenceArea);//from w w w.j a va 2 s.c om row1.add(Box.createHorizontalGlue()); JPanel row2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); row2.setBorder(BorderFactory.createTitledBorder("Target Databases")); final JList databaseList = new JList(); JScrollPane listScroller = new JScrollPane(databaseList); listScroller.setMaximumSize(new Dimension(100, 10)); JButton loadDBButton = new JButton("Load Databases"); row2.add(listScroller); row2.add(loadDBButton); JPanel row3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); JCheckBox onlyActiveCheckBox = new JCheckBox("Only Active"); onlyActiveCheckBox.setSelected(true); row3.add(new JLabel("Options: ")); row3.add(onlyActiveCheckBox); add(row1); add(row2); add(row3); final String[] columns = new String[] { "Database", "Accession", "Version", "Taxon ID" }; final JTable dataTable = new JTable(new Object[0][0], columns); dataTable.setShowGrid(true); add(new JScrollPane(dataTable)); JPanel buttonPanel = new JPanel(); JButton mapAccessionButton = new JButton("Generate Mapping!"); buttonPanel.add(mapAccessionButton); add(buttonPanel); //create listeners! //update boolean flag in communication class onlyActiveCheckBox.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { client.setOnlyActive(((JCheckBox) e.getSource()).isSelected()); } }); //performs mapping call and updates interface with results mapAccessionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (!"".equals(sequenceArea.getText())) { //TODO filters and database are hardcoded here. They should be added to the input panel at a later revision. java.util.List<UPEntry> entries = client.performBlastMapping(sequenceArea.getText(), databaseList.getSelectedValues(), "90", "", "IDENTITY", "UniprotKB", "", false, new BlastParameter()); //compute size of array if (entries != null) { int size = 0; for (UPEntry entry : entries) { for (CrossReference xref : entry.getIdenticalCrossReferences()) { size++; } for (CrossReference xref : entry.getLogicalCrossReferences()) { size++; } } if (size > 0) { final Object[][] data = new Object[size][4]; int i = 0; for (UPEntry entry : entries) { for (CrossReference xref : entry.getIdenticalCrossReferences()) { data[i][0] = xref.getDatabaseName(); data[i][1] = xref.getAccession(); data[i][2] = xref.getAccessionVersion(); data[i][3] = xref.getTaxonId(); i++; } for (CrossReference xref : entry.getLogicalCrossReferences()) { data[i][0] = xref.getDatabaseName(); data[i][1] = xref.getAccession(); data[i][2] = xref.getAccessionVersion(); data[i][3] = xref.getTaxonId(); i++; } } //refresh DefaultTableModel dataModel = new DefaultTableModel(); dataModel.setDataVector(data, columns); dataTable.setModel(dataModel); System.out.println("update done"); } else { JOptionPane.showMessageDialog(null, "No Mappind data found."); } } else { JOptionPane.showMessageDialog(null, "No Mappind data found."); } } else { JOptionPane.showMessageDialog(null, "You must enter a valid FASTA sequence to map."); } } catch (SOAPFaultException soapEx) { JOptionPane.showMessageDialog(null, "A SOAP Error occurred."); soapEx.printStackTrace(); } } }); //loads list of mapping databases from communication class loadDBButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { java.util.List<String> databases = client.loadDatabases(); if (databases != null && databases.size() > 0) { databaseList.setListData(databases.toArray()); System.out.println("database refresh done"); } else { JOptionPane.showMessageDialog(null, "No Databases Loaded!."); } } catch (SOAPFaultException soapEx) { JOptionPane.showMessageDialog(null, "A SOAP Error occurred."); soapEx.printStackTrace(); } } }); }
From source file:BoxLayoutPane.java
public BoxLayoutPane() { // Use a BorderLayout layout manager to arrange various Box components this.setLayout(new BorderLayout()); // Give the entire panel a margin by adding an empty border // We could also do this by overriding getInsets() this.setBorder(new EmptyBorder(10, 10, 10, 10)); // Add a plain row of buttons along the top of the pane Box row = Box.createHorizontalBox(); for (int i = 0; i < 4; i++) { JButton b = new JButton("B" + i); b.setFont(new Font("serif", Font.BOLD, 12 + i * 2)); row.add(b);/*w w w . ja v a 2 s . com*/ } this.add(row, BorderLayout.NORTH); // Add a plain column of buttons along the right edge // Use BoxLayout with a different kind of Swing container // Give the column a border: can't do this with the Box class JPanel col = new JPanel(); col.setLayout(new BoxLayout(col, BoxLayout.Y_AXIS)); col.setBorder(new TitledBorder(new EtchedBorder(), "Column")); for (int i = 0; i < 4; i++) { JButton b = new JButton("Button " + i); b.setFont(new Font("sanserif", Font.BOLD, 10 + i * 2)); col.add(b); } this.add(col, BorderLayout.EAST); // Add column to right of panel // Add a button box along the bottom of the panel. // Use "Glue" to space the buttons evenly Box buttonbox = Box.createHorizontalBox(); buttonbox.add(Box.createHorizontalGlue()); // stretchy space buttonbox.add(new JButton("Okay")); buttonbox.add(Box.createHorizontalGlue()); // stretchy space buttonbox.add(new JButton("Cancel")); buttonbox.add(Box.createHorizontalGlue()); // stretchy space buttonbox.add(new JButton("Help")); buttonbox.add(Box.createHorizontalGlue()); // stretchy space this.add(buttonbox, BorderLayout.SOUTH); // Create a component to display in the center of the panel JTextArea textarea = new JTextArea(); textarea.setText("This component has 12-pixel margins on left and top" + " and has 72-pixel margins on right and bottom."); textarea.setLineWrap(true); textarea.setWrapStyleWord(true); // Use Box objects to give the JTextArea an unusual spacing // First, create a column with 3 kids. The first and last kids // are rigid spaces. The middle kid is the text area Box fixedcol = Box.createVerticalBox(); fixedcol.add(Box.createVerticalStrut(12)); // 12 rigid pixels fixedcol.add(textarea); // Component fills in the rest fixedcol.add(Box.createVerticalStrut(72)); // 72 rigid pixels // Now create a row. Give it rigid spaces on the left and right, // and put the column from above in the middle. Box fixedrow = Box.createHorizontalBox(); fixedrow.add(Box.createHorizontalStrut(12)); fixedrow.add(fixedcol); fixedrow.add(Box.createHorizontalStrut(72)); // Now add the JTextArea in the column in the row to the panel this.add(fixedrow, BorderLayout.CENTER); }
From source file:org.jdal.swing.list.ListView.java
/** * {@inheritDoc}//from w ww. j a v a2 s. co m */ protected JComponent buildPanel() { BoxFormBuilder fb = new BoxFormBuilder(); fb.row(); fb.startBox(); fb.setFixedHeight(true); fb.row(); fb.add(new JButton(new AddCommandAction()), 25); fb.add(new JButton(new RemoveCommandAction()), 25); fb.add(Box.createHorizontalGlue()); fb.endBox(); fb.row(Short.MAX_VALUE); fb.add(new JScrollPane(list)); return fb.getForm(); }
From source file:ExpenseReport.java
public ExpenseReport() { super("Expense Report"); setSize(570, 200);// w w w. ja v a2s . co m m_data = new ExpenseReportData(this); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); for (int k = 0; k < ExpenseReportData.m_columns.length; k++) { TableCellRenderer renderer; if (k == ExpenseReportData.COL_APPROVED) renderer = new CheckCellRenderer(); else { DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer(); textRenderer.setHorizontalAlignment(ExpenseReportData.m_columns[k].m_alignment); renderer = textRenderer; } TableCellEditor editor; if (k == ExpenseReportData.COL_CATEGORY) editor = new DefaultCellEditor(new JComboBox(ExpenseReportData.CATEGORIES)); else if (k == ExpenseReportData.COL_APPROVED) editor = new DefaultCellEditor(new JCheckBox()); else editor = new DefaultCellEditor(new JTextField()); TableColumn column = new TableColumn(k, ExpenseReportData.m_columns[k].m_width, renderer, editor); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(false); JScrollPane ps = new JScrollPane(); ps.setSize(550, 150); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); ImageIcon penny = new ImageIcon("penny.gif"); m_title = new JLabel("Total: $", penny, JButton.LEFT); m_title.setForeground(Color.black); m_title.setAlignmentY(0.5f); p.add(m_title); p.add(Box.createHorizontalGlue()); JButton bt = new JButton("Insert before"); bt.setMnemonic('b'); bt.setAlignmentY(0.5f); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row); m_table.tableChanged( new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Insert after"); bt.setMnemonic('a'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row + 1); m_table.tableChanged(new TableModelEvent(m_data, row + 1, row + 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Delete row"); bt.setMnemonic('d'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); if (m_data.delete(row)) { m_table.tableChanged(new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); calcTotal(); } } }; bt.addActionListener(lst); p.add(bt); getContentPane().add(p, BorderLayout.SOUTH); calcTotal(); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }