List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:Main.java
public Main() { super("Test"); setSize(200, 200);//from w w w. ja v a2 s . c o m JPanel panel = new JPanel(); setContentPane(panel); JButton button1 = new JButton("Button 1"); JButton button2 = new JButton("Button 2"); JButton button3 = new JButton("Button 3"); button1.setBounds(10, 10, 100, 40); button2.setBounds(5, 5, 100, 30); button3.setBounds(15, 15, 150, 40); panel.setLayout(null); panel.add(button1); panel.add(button2); panel.add(button3); panel.setComponentZOrder(button1, 1); panel.setComponentZOrder(button2, 0); panel.setComponentZOrder(button3, 2); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); }
From source file:LightBug.java
JPanel lightPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(0, 1)); panel.add(new JLabel("Light type")); // create the buttons JRadioButton lightNoneButton = new JRadioButton(lightNoneString); JRadioButton lightDirectionalButton = new JRadioButton(lightDirectionalString); JRadioButton lightPointButton = new JRadioButton(lightPointString); JRadioButton lightSpotButton = new JRadioButton(lightSpotString); // set up the action commands lightNoneButton.setActionCommand(lightNoneString); lightDirectionalButton.setActionCommand(lightDirectionalString); lightPointButton.setActionCommand(lightPointString); lightSpotButton.setActionCommand(lightSpotString); // add the buttons to a group so that only one can be selected ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(lightNoneButton);/*from www . ja va2 s . c o m*/ buttonGroup.add(lightDirectionalButton); buttonGroup.add(lightPointButton); buttonGroup.add(lightSpotButton); // register the applet as the listener for the buttons lightNoneButton.addActionListener(this); lightDirectionalButton.addActionListener(this); lightPointButton.addActionListener(this); lightSpotButton.addActionListener(this); // add the buttons to the panel panel.add(lightNoneButton); panel.add(lightDirectionalButton); panel.add(lightPointButton); panel.add(lightSpotButton); // set the default lightDirectionalButton.setSelected(true); return panel; }
From source file:flexflux.analyses.result.TDRFBAResult.java
public void plot() { JPanel panel = new JPanel(); JScrollPane sp = new JScrollPane(panel); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); // one chart by entity Color[] colors = new Color[] { Color.RED, Color.GREEN, Color.BLUE }; int index = 0; for (String s : entities) { XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries(s); for (Double time : times) { series.add(time, resultMap.get(time).get(s)); }// ww w . j a v a 2s . c om final JFreeChart chart = ChartFactory.createXYLineChart(s, // chart // title "Time (h)", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.GRAY); plot.setDomainGridlinePaint(Color.GRAY); plot.getRenderer().setSeriesPaint(0, colors[index % colors.length]); index++; ChartPanel chartPanel = new ChartPanel(chart); dataset.addSeries(series); panel.add(chartPanel); panel.add(new JSeparator()); } Dimension d = panel.getComponent(0).getPreferredSize(); d.height *= 2; sp.getViewport().setPreferredSize(d); JFrame frame = new JFrame("Time-dependant FBA results"); frame.add(sp); frame.pack(); RefineryUtilities.centerFrameOnScreen(frame); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:SoundBug.java
JPanel soundPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(4, 1)); // create the buttons soundNoneButton = new JRadioButton(soundNoneString); soundBackgroundButton = new JRadioButton(soundBackgroundString); soundPointButton = new JRadioButton(soundPointString); //soundConeButton = new JRadioButton(soundConeString); // set up the action commands soundNoneButton.setActionCommand(soundNoneString); soundBackgroundButton.setActionCommand(soundBackgroundActionString); soundPointButton.setActionCommand(soundPointActionString); //soundConeButton.setActionCommand(soundConeString); // add the buttons to a group so that only one can be selected ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(soundNoneButton);/*from ww w . j a v a2 s. co m*/ buttonGroup.add(soundBackgroundButton); buttonGroup.add(soundPointButton); //buttonGroup.add(soundConeButton); // register the applet as the listener for the buttons soundNoneButton.addActionListener(this); soundBackgroundButton.addActionListener(this); soundPointButton.addActionListener(this); // soundConeButton.addActionListener(this); // add the buttons to the panel panel.add(soundNoneButton); panel.add(soundBackgroundButton); panel.add(soundPointButton); //panel.add(soundConeButton); // set the default soundNoneButton.setSelected(true); return panel; }
From source file:hermes.browser.dialog.GeneralRendererConfigPanel.java
private void init() { Border border = BorderFactory.createBevelBorder(BevelBorder.RAISED); JPanel topPanel = new JPanel(); topPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); topPanel.setLayout(new GridLayout(1, 2)); infoLabel1.setText("Message Renderers"); setLayout(new BorderLayout()); setBorder(BorderFactory.createTitledBorder(border, "Renderers")); topPanel.add(infoLabel1);//w ww .j a v a2s . co m topSP.setViewportView(classTable); classTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); add(topPanel, BorderLayout.NORTH); add(splitPane, BorderLayout.CENTER); splitPane.add(topSP, "top"); splitPane.add(bottomSP, "bottom"); splitPane.setDividerLocation(200); // splitPane.setShowGripper(true) ; classTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { doRendererSelected(e); } }); }
From source file:net.pandoragames.far.ui.swing.component.ButtonPanel.java
/** * Initialises the BUTTON panel./*w w w. j a v a 2s . c o m*/ * @param config configuration properties * @param componentRepository repository for shared components */ private JPanel initButtonPannel(SwingConfig config, ComponentRepository componentRepository) { JPanel buttonPannel = new JPanel(); buttonPannel.setAlignmentX(Component.LEFT_ALIGNMENT); buttonPannel.setLayout(new FlowLayout(FlowLayout.TRAILING)); // FIND if (operationType == OperationType.FIND) { JButton findButton = new JButton(localizer.localize("button.find")); componentRepository.getOperationCallBackListener().addComponentStartDisabled(findButton, OperationType.FIND); componentRepository.getOperationCallBackListener().addComponentTerminationEnabled(findButton, OperationType.FIND); findButton.addActionListener(componentRepository.getFindCommand()); findButton.addActionListener(new ReorderFilePatternListListener(componentRepository.getFindForm(), config.getFileNamePatternListModel())); buttonPannel.add(findButton); } // REPLACE if (operationType == OperationType.REPLACE) { JButton replaceButton = new JButton(localizer.localize("button.replace")); replaceButton.setEnabled(false); componentRepository.getOperationCallBackListener().addComponentTerminationEnabled(replaceButton, OperationType.FIND); componentRepository.getResetDispatcher().addToBeDisabled(replaceButton); componentRepository.getSearchBaseListener().addToBeDisabled(replaceButton); ConfirmReplaceListener replaceListener = new ConfirmReplaceListener(componentRepository.getRootWindow(), config, componentRepository.getReplaceForm()); replaceListener.addActionListener(componentRepository.getReplaceCommand()); replaceButton.addActionListener(replaceListener); buttonPannel.add(replaceButton); } // RENAME if (operationType == OperationType.RENAME) { JButton renameButton = new JButton(componentRepository.getRenameCommand()); renameButton.setEnabled(false); componentRepository.getResetDispatcher().addToBeDisabled(renameButton); buttonPannel.add(renameButton); } // CANCEL JButton cancelButton = new JButton(localizer.localize("button.cancel")); cancelButton.setEnabled(false); componentRepository.getOperationCallBackListener().addComponentStartEnabled(cancelButton, OperationType.ANY); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { backend.abort(); } }); buttonPannel.add(cancelButton); componentRepository.getResetDispatcher().addToBeDisabled(cancelButton); // UNDO if (operationType == OperationType.REPLACE) { JButton undoButton = new JButton(localizer.localize("button.undo")); undoButton.setEnabled(false); componentRepository.getOperationCallBackListener().addComponentTerminationEnabled(undoButton, OperationType.REPLACE); componentRepository.getOperationCallBackListener().addComponentStartDisabled(undoButton, OperationType.FIND); undoButton.addActionListener(componentRepository.getUndoListener()); undoButton.addActionListener(new OnClickDisable(undoButton)); buttonPannel.add(undoButton); } // RESET JButton clearButton = new JButton(localizer.localize("button.reset")); clearButton.addActionListener(componentRepository.getResetDispatcher()); buttonPannel.add(clearButton); // this.add( buttonPannel ); return buttonPannel; }
From source file:DragListDemo.java
public DragListDemo() { arrayListHandler = new ArrayListTransferHandler(); JList list1, list2;/*ww w . ja v a 2 s . co m*/ DefaultListModel list1Model = new DefaultListModel(); list1Model.addElement("0 (list 1)"); list1Model.addElement("1 (list 1)"); list1Model.addElement("2 (list 1)"); list1Model.addElement("3 (list 1)"); list1Model.addElement("4 (list 1)"); list1Model.addElement("5 (list 1)"); list1Model.addElement("6 (list 1)"); list1 = new JList(list1Model); list1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); list1.setTransferHandler(arrayListHandler); list1.setDragEnabled(true); JScrollPane list1View = new JScrollPane(list1); list1View.setPreferredSize(new Dimension(200, 100)); JPanel panel1 = new JPanel(); panel1.setLayout(new BorderLayout()); panel1.add(list1View, BorderLayout.CENTER); panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); DefaultListModel list2Model = new DefaultListModel(); list2Model.addElement("0 (list 2)"); list2Model.addElement("1 (list 2)"); list2Model.addElement("2 (list 2)"); list2Model.addElement("3 (list 2)"); list2Model.addElement("4 (list 2)"); list2Model.addElement("5 (list 2)"); list2Model.addElement("6 (list 2)"); list2 = new JList(list2Model); list2.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); list2.setTransferHandler(arrayListHandler); list2.setDragEnabled(true); JScrollPane list2View = new JScrollPane(list2); list2View.setPreferredSize(new Dimension(200, 100)); JPanel panel2 = new JPanel(); panel2.setLayout(new BorderLayout()); panel2.add(list2View, BorderLayout.CENTER); panel2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setLayout(new BorderLayout()); add(panel1, BorderLayout.LINE_START); add(panel2, BorderLayout.LINE_END); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:EditorPaneExample6.java
public EditorPaneExample6() { super("JEditorPane Example 6"); pane = new JEditorPane(); pane.setEditable(false); // Start read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;//from w ww. j a v a2 s .c om c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("File name: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; textField = new JTextField(32); panel.add(textField, c); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; c.gridwidth = 2; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); // Add a "Save" button saveButton = new JButton("Save"); saveButton.setEnabled(false); c.gridwidth = 1; c.gridx = 2; c.gridy = 0; c.weightx = 0.0; panel.add(saveButton, c); getContentPane().add(panel, "South"); // Change page based on text field textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String fileName = textField.getText().trim(); file = new File(fileName); absolutePath = file.getAbsolutePath(); String url = "file:///" + absolutePath; try { // Check if the new page and the old // page are the same. URL newURL = new URL(url); URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(newURL)) { return; } // Try to display the page textField.setEnabled(false); // Disable input textField.paintImmediately(0, 0, textField.getSize().width, textField.getSize().height); saveButton.setEnabled(false); saveButton.paintImmediately(0, 0, saveButton.getSize().width, saveButton.getSize().height); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Busy cursor loadingState.setText("Loading..."); loadingState.paintImmediately(0, 0, loadingState.getSize().width, loadingState.getSize().height); loadedType.setText(""); loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height); pane.setEditable(false); pane.setPage(url); loadedType.setText(pane.getContentType()); } catch (Exception e) { JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); textField.setEnabled(true); setCursor(Cursor.getDefaultCursor()); } } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadingState.setText("Page loaded."); textField.setEnabled(true); // Allow entry of new file name textField.requestFocus(); setCursor(Cursor.getDefaultCursor()); // Allow editing and saving if appropriate pane.setEditable(file.canWrite()); saveButton.setEnabled(file.canWrite()); } } }); // Save button saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { String type = pane.getContentType(); OutputStream os = new BufferedOutputStream(new FileOutputStream(file + ".save")); pane.setEditable(false); textField.setEnabled(false); saveButton.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Document doc = pane.getDocument(); int length = doc.getLength(); if (type.endsWith("/rtf")) { // Saving RTF - use the OutputStream try { pane.getEditorKit().write(os, doc, 0, length); os.close(); } catch (BadLocationException ex) { } } else { // Not RTF - use a Writer. Writer w = new OutputStreamWriter(os); pane.write(w); w.close(); } } catch (IOException e) { JOptionPane.showMessageDialog(pane, new String[] { "Unable to save file", file.getAbsolutePath(), }, "File Save Error", JOptionPane.ERROR_MESSAGE); } pane.setEditable(file.canWrite()); textField.setEnabled(true); saveButton.setEnabled(file.canWrite()); setCursor(Cursor.getDefaultCursor()); } }); }
From source file:Cal.java
/** Build the GUI. Assumes that setYYMMDD has been called. */ private void buildGUI() { getAccessibleContext().setAccessibleDescription("Calendar not accessible yet. Sorry!"); setBorder(BorderFactory.createEtchedBorder()); setLayout(new BorderLayout()); JPanel tp = new JPanel(); tp.add(monthChoice = new JComboBox()); for (int i = 0; i < months.length; i++) monthChoice.addItem(months[i]);//from www .j av a2s . c o m monthChoice.setSelectedItem(months[mm]); monthChoice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int i = monthChoice.getSelectedIndex(); if (i >= 0) { mm = i; // System.out.println("Month=" + mm); recompute(); } } }); monthChoice.getAccessibleContext().setAccessibleName("Months"); monthChoice.getAccessibleContext().setAccessibleDescription("Choose a month of the year"); tp.add(yearChoice = new JComboBox()); yearChoice.setEditable(true); for (int i = yy - 5; i < yy + 5; i++) yearChoice.addItem(Integer.toString(i)); yearChoice.setSelectedItem(Integer.toString(yy)); yearChoice.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int i = yearChoice.getSelectedIndex(); if (i >= 0) { yy = Integer.parseInt(yearChoice.getSelectedItem().toString()); // System.out.println("Year=" + yy); recompute(); } } }); add(BorderLayout.CENTER, tp); JPanel bp = new JPanel(); bp.setLayout(new GridLayout(7, 7)); labs = new JButton[6][7]; // first row is days bp.add(b0 = new JButton("S")); bp.add(new JButton("M")); bp.add(new JButton("T")); bp.add(new JButton("W")); bp.add(new JButton("R")); bp.add(new JButton("F")); bp.add(new JButton("S")); ActionListener dateSetter = new ActionListener() { public void actionPerformed(ActionEvent e) { String num = e.getActionCommand(); if (!num.equals("")) { // set the current day highlighted setDayActive(Integer.parseInt(num)); // When this becomes a Bean, you can // fire some kind of DateChanged event here. // Also, build a similar daySetter for day-of-week btns. } } }; // Construct all the buttons, and add them. for (int i = 0; i < 6; i++) for (int j = 0; j < 7; j++) { bp.add(labs[i][j] = new JButton("")); labs[i][j].addActionListener(dateSetter); } add(BorderLayout.SOUTH, bp); }
From source file:com.apatar.webdav.ui.JWebDavTreeModePanel.java
private void createPanel() { setLayout(new BorderLayout(5, 5)); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); add(panel, BorderLayout.CENTER); title = new JLabel(""); panel.add(title);/*w w w . j av a 2 s . co m*/ labelPath = new JLabel(WORD_PATH); panel.add(labelPath); panel.add(getFoldersPanel()); }