List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:Main.java
public Main() { super(new BorderLayout()); listModel.addElement("A"); listModel.addElement("B"); listModel.addElement("C"); list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);/*from w w w .j a v a 2 s . co m*/ list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(addCommand); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(addCommand); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(deleteCommand); fireButton.setActionCommand(deleteCommand); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); System.out.println(name); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.heatmap.HeatMapImgGenerator.java
public String generateHeatmap(String[] rows, String[] columns, String[][] data) { JPanel heatmapPanelLayout = new JPanel(); heatmapPanelLayout.setLayout(null); heatmapPanelLayout.setVisible(true); int width = (columns.length + 1) * 50; int height = (rows.length + 1) * 50; heatmapPanelLayout.setSize(width, height); JPanel cornerCell = initCell("#ffffff", 0, 0); int x = 50;//from www. j a va 2 s .c o m int y = 0; heatmapPanelLayout.add(cornerCell); for (String headerCell : columns) { JPanel cell = initCell(headerCell, x, y); x += 50; heatmapPanelLayout.add(cell); } y = 50; for (String headerCell : rows) { JPanel cell = initCell(headerCell, 0, y); y += 50; heatmapPanelLayout.add(cell); } x = 50; y = 50; for (String[] row : data) { for (String color : row) { JPanel cell = initCell(color, x, y); heatmapPanelLayout.add(cell); x += 50; } x = 50; y += 50; } BufferedImage image = new BufferedImage(width + 10, height + 10, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setPaint(Color.WHITE); graphics.setBackground(Color.WHITE); heatmapPanelLayout.paint(graphics); byte[] imageData = null; try { ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f)); imageData = in.encode(image); } catch (Exception e) { System.out.println(e.getLocalizedMessage()); } String base64 = Base64.encodeBytes(imageData); base64 = "data:image/png;base64," + base64; return base64; }
From source file:com.jdom.util.patterns.mvp.swing.RadioButtonGroupDialog.java
private RadioButtonGroupDialog(Frame frame, Component locationComp, String labelText, String title, Collection<String> data, String initialValue, String longValue) { super(frame, title, true); final JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); final JButton setButton = new JButton("OK"); setButton.setActionCommand("OK"); setButton.addActionListener(this); getRootPane().setDefaultButton(setButton); ButtonGroup radioButtonGroup = new ButtonGroup(); for (String option : data) { JRadioButton button = new JRadioButton(option); if (option.equals(initialValue)) { button.setSelected(true);//from ww w .j av a 2 s. c om } radioButtonGroup.add(button); panel.add(button); } JScrollPane listScroller = new JScrollPane(panel); listScroller.setPreferredSize(new Dimension(250, 80)); listScroller.setAlignmentX(LEFT_ALIGNMENT); JPanel listPane = new JPanel(); listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); if (!StringUtils.isEmpty(labelText)) { JLabel label = new JLabel(labelText); label.setText(labelText); listPane.add(label); } listPane.add(Box.createRigidArea(new Dimension(0, 5))); listPane.add(listScroller); listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(cancelButton); buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(setButton); Container contentPane = getContentPane(); contentPane.add(listPane, BorderLayout.CENTER); contentPane.add(buttonPane, BorderLayout.PAGE_END); pack(); setLocationRelativeTo(locationComp); }
From source file:House.java
public House() { super(new BorderLayout()); JPanel controlPanel = new JPanel(new GridLayout(3, 3)); add(controlPanel, BorderLayout.NORTH); controlPanel.add(new JLabel("Translate(dx,dy): ")); sliderTransX = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50); sliderTransY = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 300, 150, 100, 50); // To control rotation controlPanel.add(new JLabel("Rotate(Theta,ox,oy): ")); sliderRotateTheta = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 360, 0, 90, 45); JPanel subPanel = new JPanel(); subPanel.setLayout(new GridLayout(1, 2)); sliderRotateX = setSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50); sliderRotateY = setSlider(subPanel, JSlider.HORIZONTAL, 0, 300, 150, 150, 50); controlPanel.add(subPanel);// w w w . jav a 2 s .com // To control scaling controlPanel.add(new JLabel("Scale(sx,sy)x10E-2:")); sliderScaleX = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10); sliderScaleY = setSlider(controlPanel, JSlider.HORIZONTAL, 0, 200, 100, 100, 10); // To control width of line segments JLabel label4 = new JLabel("Width Control:", JLabel.RIGHT); sliderWidth = new JSlider(JSlider.HORIZONTAL, 0, 20, 1); sliderWidth.setPaintTicks(true); sliderWidth.setMajorTickSpacing(5); sliderWidth.setMinorTickSpacing(1); sliderWidth.setPaintLabels(true); sliderWidth.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { width = sliderWidth.getValue(); canvas.repaint(); } }); JPanel widthPanel = new JPanel(); widthPanel.setLayout(new GridLayout(1, 2)); widthPanel.add(label4); widthPanel.add(sliderWidth); add(widthPanel, BorderLayout.SOUTH); canvas = new MyCanvas(); add(canvas, "Center"); }
From source file:iad_zad3.gui.ChartWorker.java
private void updateVoronoi() { VoronoiPanel vPanel = new VoronoiPanel(); for (Pnt p : GUIHelper.getVoronoiPoints(clusteringAlgorithm)) { vPanel.addSite(p);/*w w w . j a v a 2s. c om*/ } JPanel tmpPanel = new JPanel(); tmpPanel.setSize(new Dimension(700, 700)); tmpPanel.setLayout(new BorderLayout()); voronoiPanel.add(tmpPanel, "Center"); tmpPanel.add(vPanel, "Center"); voronoiPanel.revalidate(); }
From source file:cl.almejo.vsim.gui.actions.preferences.ColorPreferences.java
public ColorPreferences(Component parent) { _parent = parent;/*ww w.java2 s.com*/ setBorder(new EmptyBorder(10, 10, 10, 10)); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel pickers = new JPanel(); pickers.setLayout(new GridLayout(10, 2)); pickers.add(new Label(Messages.t("preferences.color.scheme.current.label"))); _comboBox = createSchemeCombobox(); pickers.add(_comboBox); addColorChooser(pickers, "gates"); addColorChooser(pickers, "background"); addColorChooser(pickers, "bus-on"); addColorChooser(pickers, "ground"); addColorChooser(pickers, "off"); addColorChooser(pickers, "wires-on"); addColorChooser(pickers, "signal"); addColorChooser(pickers, "grid"); addColorChooser(pickers, "label"); add(pickers); JPanel buttons = new JPanel(); JButton button = new JButton(Messages.t("preferences.color.scheme.save.label")); buttons.add(button); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { FileUtils.writeStringToFile(new File("colors.json"), ColorScheme.save()); } catch (IOException e1) { e1.printStackTrace(); } } }); button = new JButton(Messages.t("preferences.color.scheme.new.label")); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String themeName = JOptionPane.showInputDialog(Messages.t("color.scheme.dialog.new.title"), ""); if (themeName != null) { while (ColorScheme.exists(themeName)) { JOptionPane.showMessageDialog(_parent, Messages.t("color.scheme.dialog.already.exists.error"), "Error", JOptionPane.ERROR_MESSAGE); themeName = JOptionPane.showInputDialog(this, themeName); } ColorScheme.add(themeName); _comboBox.addItem(themeName); _comboBox.setSelectedItem(themeName); } } }); buttons.add(button); add(buttons); }
From source file:com.floreantpos.ui.views.payment.GiftCertDialog.java
public GiftCertDialog(JDialog parent) { super();/*w w w . jav a 2 s . c o m*/ setTitle(Messages.getString("GiftCertDialog.0")); //$NON-NLS-1$ setTitlePaneText(Messages.getString("GiftCertDialog.1")); JPanel panel = getContentPanel(); getContentPane().add(panel, BorderLayout.CENTER); panel.setLayout(new MigLayout("", "[][grow]", "[][]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ JLabel lblGiftCertificateNumber = new JLabel(Messages.getString("GiftCertDialog.5")); //$NON-NLS-1$ panel.add(lblGiftCertificateNumber, "cell 0 0,alignx trailing"); //$NON-NLS-1$ tfGiftCertNumber = new FixedLengthTextField(); tfGiftCertNumber.setLength(64); panel.add(tfGiftCertNumber, "cell 1 0,growx"); //$NON-NLS-1$ JLabel lblFaceValue = new JLabel(Messages.getString("GiftCertDialog.8")); //$NON-NLS-1$ panel.add(lblFaceValue, "cell 0 1,alignx trailing"); //$NON-NLS-1$ tfFaceValue = new DoubleTextField(); tfFaceValue.setText("50"); //$NON-NLS-1$ panel.add(tfFaceValue, "cell 1 1,growx"); //$NON-NLS-1$ qwertyKeyPad = new QwertyKeyPad(); panel.add(qwertyKeyPad, "newline, gaptop 10px, span"); //$NON-NLS-1$ }
From source file:net.sf.maltcms.chromaui.normalization.spi.actions.OpenPeakGroupRtBoxPlot.java
@Override public void actionPerformed(ActionEvent ev) { IChromAUIProject project = Utilities.actionsGlobalContext().lookup(IChromAUIProject.class); if (project != null && !context.isEmpty()) { PeakGroupBoxPlotTopComponent pgbpt = new PeakGroupBoxPlotTopComponent(); PeakGroupRtBoxPlot pgbp = new PeakGroupRtBoxPlot(project, context); JPanel bg = new JPanel(); BoxLayout bl = new BoxLayout(bg, BoxLayout.Y_AXIS); bg.setLayout(bl); for (JFreeChart chart : pgbp.createChart()) { ChartPanel cp = new ContextAwareChartPanel(chart); bg.add(cp);//from www . j av a 2 s . c om } JScrollPane jsp = new JScrollPane(bg); pgbpt.add(jsp, BorderLayout.CENTER); IRegistry registry = Lookup.getDefault().lookup(IRegistryFactory.class).getDefault(); for (IPeakGroupDescriptor pgd : context) { registry.registerTopComponentFor(pgd, pgbpt); } pgbpt.open(); pgbpt.requestActive(); } else { Logger.getLogger(getClass().getName()).warning("No IChromAUI project is in lookup!"); } }
From source file:com.emental.mindraider.ui.dialogs.DownloadModelJDialog.java
/** * Constructor.//from w w w .jav a 2s. com * * @param union * made union of models. */ public DownloadModelJDialog(boolean union) { super(Messages.getString("DownloadModelJDialog.title")); JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 5)); p.add(new JLabel(Messages.getString("DownloadModelJDialog.url"))); String[] knowUris = new String[] { "http://", "http://wymiwyg.org/", "http://www.osar.ch", "http://wymiwyg.org/.rdf?appendLang=en&till=50", "http://www.osar.ch/.rdf?appendLang=de&till=50" }; modelUrlCombo = new JComboBox(knowUris); modelUrlCombo.setEditable(true); modelUrlCombo.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent keyEvent) { if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) { upload(); } } public void keyReleased(KeyEvent keyEvent) { } public void keyTyped(KeyEvent keyEvent) { } }); p.add(modelUrlCombo); JButton uploadButton = new JButton(Messages.getString("DownloadModelJDialog.download")); uploadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { upload(); } }); p.add(uploadButton); JButton cancelButton = new JButton(Messages.getString("DownloadModelJDialog.cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); p.add(cancelButton); getContentPane().add(p, BorderLayout.CENTER); // show pack(); Gfx.centerAndShowWindow(this); }
From source file:com.apatar.ui.JHelpDialog.java
private void createDialog() { setLayout(new BorderLayout(5, 5)); setSize(500, 500);/*from w w w. j a va 2s. c om*/ JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.add(Box.createHorizontalGlue()); buttonPanel.add(sendButton); getContentPane().add(text, BorderLayout.CENTER); getContentPane().add(buttonPanel, BorderLayout.SOUTH); }