List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:components.ListDemo.java
public ListDemo() { super(new BorderLayout()); listModel = new DefaultListModel(); listModel.addElement("Jane Doe"); listModel.addElement("John Smith"); listModel.addElement("Kathy Green"); //Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);/*from w w w .j a va 2 s . c om*/ list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(hireString); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(hireString); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(fireString); fireButton.setActionCommand(fireString); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); //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:BoxAlignmentDemo.java
protected JPanel createButtonRow(boolean changeAlignment) { JButton button1 = new JButton("A JButton", createImageIcon("images/middle.gif")); button1.setVerticalTextPosition(AbstractButton.BOTTOM); button1.setHorizontalTextPosition(AbstractButton.CENTER); JButton button2 = new JButton("Another JButton", createImageIcon("images/geek-cght.gif")); button2.setVerticalTextPosition(AbstractButton.BOTTOM); button2.setHorizontalTextPosition(AbstractButton.CENTER); String title;/* ww w. j a v a 2s. c o m*/ if (changeAlignment) { title = "Desired"; button1.setAlignmentY(BOTTOM_ALIGNMENT); button2.setAlignmentY(BOTTOM_ALIGNMENT); } else { title = "Default"; } JPanel pane = new JPanel(); pane.setBorder(BorderFactory.createTitledBorder(title)); pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS)); pane.add(button1); pane.add(button2); return pane; }
From source file:soap.ui.panel.innerCentralPanel.StatsPanel.java
protected void initUI() { if (mIndicatorsName.size() != 0) { defaultAddComponent(new JLabel(resMan.getString("statsChooseIndicator")), SoapGridbagPanel.END); JPanel indicatorsPanel = new JPanel(); indicatorsPanel.setBackground(Color.WHITE); indicatorsPanel.setLayout(new GridLayout(mIndicatorsName.size(), 1)); mCheckBoxTable = new JCheckBox[mIndicatorsName.size()]; CheckBoxListener listener = new CheckBoxListener(); Iterator it = mIndicatorsName.keySet().iterator(); for (int i = 0; i < mIndicatorsName.size(); i++) { String key = (String) it.next(); mCheckBoxTable[i] = new JCheckBox((String) mIndicatorsName.get(key)); mCheckBoxTable[i].setName(key); mCheckBoxTable[i].setPreferredSize(new Dimension(50, 20)); mCheckBoxTable[i].setBackground(Color.WHITE); mCheckBoxTable[i].addItemListener(listener); indicatorsPanel.add(mCheckBoxTable[i]); }/* w ww . j a va2 s. com*/ JScrollPane scrollPane = new JScrollPane(indicatorsPanel); scrollPane.setPreferredSize(new Dimension(140, 65)); defaultAddComponent(scrollPane, SoapGridbagPanel.END, 1, 0, new Insets(10, 0, 20, 0)); // add the chart to a panel... mChartPanel.setPreferredSize(new Dimension(580, 330)); defaultAddComponent(new JScrollPane(mChartPanel), SoapGridbagPanel.END); } }
From source file:com.emental.mindraider.ui.dialogs.AddLinkToConceptJDialog.java
/** * Constructor./*from www.j a va 2 s .c o m*/ */ public AddLinkToConceptJDialog() { super("Add Link To Note"); JPanel framePanel = new JPanel(); framePanel.setLayout(new GridLayout(3, 1)); JPanel p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.RIGHT)); p.add(new JLabel(" Predicate: ")); predicateNs = new JTextField(38); predicateNs.setText("http://" + MindRaider.profile.getHostname() + "/e-mentality/conceptLink/custom#"); predicateNs.selectAll(); p.add(predicateNs); p.add(new JLabel("#")); predicateLocalName = new JTextField(15); p.add(predicateLocalName); framePanel.add(p); p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.LEFT)); p.add(new JLabel(" Note: ")); objectNs = new JTextField(38); objectNs.setText(""); objectNs.selectAll(); p.add(objectNs); findConceptButton = new JButton("Find Note"); findConceptButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { OpenNoteJDialog.NoteToOpen conceptToOpen = new OpenNoteJDialog.NoteToOpen(); new OpenNoteJDialog("OpenNoteJDialog.titleLink", "OpenNoteJDialog.selectConceptToLink", "OpenNoteJDialog.link", null, conceptToOpen); if (conceptToOpen.conceptLabel != null) { objectNs.setText(conceptToOpen.conceptUri); } } }); p.add(findConceptButton); framePanel.add(p); p = new JPanel(); p.setLayout(new FlowLayout(FlowLayout.CENTER)); JButton addButton = new JButton("Add"); p.add(addButton); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { createTriplet(); } }); JButton cancelButton = new JButton("Cancel"); p.add(cancelButton); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { AddLinkToConceptJDialog.this.dispose(); } }); framePanel.add(p); getContentPane().add(framePanel, BorderLayout.CENTER); // show pack(); Gfx.centerAndShowWindow(this); }
From source file:InternalFrameListenerDemo.java
public InternalFrameListenerDemo() { setTitle("Animated InternalFrameListener"); m_count = m_tencount = 0;//from w w w . ja v a2 s. c o m JPanel innerListenerPanel = new JPanel(new GridLayout(7, 1)); JPanel listenerPanel = new JPanel(new BorderLayout()); m_ifEventCanvas = new IFEventCanvas(); m_lOpened = new JLabel("internalFrameOpened"); m_lClosing = new JLabel("internalFrameClosing"); m_lClosed = new JLabel("internalFrameClosed"); m_lIconified = new JLabel("internalFrameIconified"); m_lDeiconified = new JLabel("internalFrameDeiconified"); m_lActivated = new JLabel("internalFrameActivated"); m_lDeactivated = new JLabel("internalFrameDeactivated"); innerListenerPanel.add(m_lOpened); innerListenerPanel.add(m_lClosing); innerListenerPanel.add(m_lClosed); innerListenerPanel.add(m_lIconified); innerListenerPanel.add(m_lDeiconified); innerListenerPanel.add(m_lActivated); innerListenerPanel.add(m_lDeactivated); listenerPanel.add("Center", m_ifEventCanvas); listenerPanel.add("West", innerListenerPanel); listenerPanel.setOpaque(true); listenerPanel.setBackground(Color.white); m_desktop = new JDesktopPane(); m_desktop.setBorder(new SoftBevelBorder(BevelBorder.LOWERED)); m_newFrame = new JButton("New Frame"); m_newFrame.addActionListener(this); m_infos = UIManager.getInstalledLookAndFeels(); String[] LAFNames = new String[m_infos.length]; for (int i = 0; i < m_infos.length; i++) { LAFNames[i] = m_infos[i].getName(); } m_UIBox = new JComboBox(LAFNames); m_UIBox.addActionListener(this); JPanel topPanel = new JPanel(true); topPanel.setLayout(new FlowLayout()); topPanel.setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED), new CompoundBorder(new EmptyBorder(2, 2, 2, 2), new SoftBevelBorder(BevelBorder.RAISED)))); getContentPane().setLayout(new BorderLayout()); getContentPane().add("North", topPanel); getContentPane().add("Center", m_desktop); getContentPane().add("South", listenerPanel); ((JPanel) getContentPane()).setBorder(new CompoundBorder(new SoftBevelBorder(BevelBorder.LOWERED), new CompoundBorder(new EmptyBorder(1, 1, 1, 1), new SoftBevelBorder(BevelBorder.RAISED)))); topPanel.add(m_newFrame); topPanel.add(new JLabel("Look & Feel:", SwingConstants.RIGHT)); topPanel.add(m_UIBox); setSize(645, 500); Dimension dim = getToolkit().getScreenSize(); setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2); setVisible(true); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(l); m_eventTimer = new Timer(1000, this); m_eventTimer.setRepeats(true); m_eventTimer.start(); }
From source file:gda.gui.scanplot.ScanPlot.java
void hideLegend(boolean hide) { this.removeAll(); if (plot instanceof Component && legendPanel instanceof Component) { this.add((Component) plot, BorderLayout.CENTER); JPanel top = new JPanel(); top.setLayout(new BorderLayout()); top.add(legendVisible, BorderLayout.EAST); this.add(top, BorderLayout.NORTH); if (!hide) this.add((Component) legendPanel, BorderLayout.EAST); ((Component) plot).setPreferredSize(new Dimension(800, 800)); if (!hide) { ((Component) legendPanel).setPreferredSize(new Dimension(200, 800)); }/*w w w . j ava 2 s . c o m*/ } this.validate(); }
From source file:ProgressDialog.java
private void setupComponent() { JPanel contentPane = (JPanel) getContentPane(); contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.gridx = 0;/*from w w w . ja va2s.c o m*/ gc.gridy = GridBagConstraints.RELATIVE; gc.anchor = GridBagConstraints.NORTHWEST; contentPane.add(lblMessage, gc); gc.weightx = 1; gc.fill = GridBagConstraints.HORIZONTAL; contentPane.add(progressBar, gc); setTitle(""); setModal(true); pack(); }
From source file:arduinoserialread.SerialRead.java
private void initGUI() { // init the frame frame.setTitle("Arduino Serial Read"); frame.setBounds(100, 100, 600, 500); frame.setMinimumSize(new Dimension(600, 500)); frame.setLocationRelativeTo(null);/*from w w w . java 2 s. co m*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // init control panel JPanel ctrlPanel = new JPanel(); ctrlPanel.setLayout(new FlowLayout()); // init the serial connection panel serialCOM = new SerialConnectionPanel(); ctrlPanel.add(serialCOM); frame.getContentPane().add(ctrlPanel, BorderLayout.SOUTH); // init the connection status ConnectionStatus connectionStatus = new ConnectionStatus(); ctrlPanel.add(connectionStatus); // init connect and disconnect button connect = new JButton("connect"); ctrlPanel.add(connect); disconnect = new JButton("disconnect"); ctrlPanel.add(disconnect); // init real time chart TimeSeries series = new TimeSeries("DATA"); DateAxis timeAxis = new DateAxis("Time"); dataset = new TimeSeriesCollection(series); NumberAxis rangeAxis = new NumberAxis("Data"); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setAutoRange(true); XYPlot plot = new XYPlot(dataset, timeAxis, rangeAxis, new StandardXYItemRenderer()); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.getRenderer().setSeriesPaint(0, new Color(0, 142, 192)); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setAutoRange(true); domainAxis.setFixedAutoRange(30000.0); // 30 seconds // init the JFreeChart JFreeChart chart = new JFreeChart("Real-Time Data Chart", plot); chart.setBorderPaint(Color.lightGray); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); chart.removeLegend(); // add real time chart to the frame ChartPanel chartPanel = new ChartPanel(chart); frame.getContentPane().add(chartPanel, BorderLayout.CENTER); }
From source file:Interfaces.EstadisticaGui.java
private void dibujarGraficos() { this.setCursor(new Cursor(Cursor.WAIT_CURSOR)); abrirBase();/* ww w .j a v a 2 s .c o m*/ panelGrande.removeAll(); Integer anio = (Integer) spinnerAnio.getValue(); // Creamos y rellenamos el modelo de datos LazyList<Categoria> categorias = Categoria.findAll(); Iterator<Categoria> it = categorias.iterator(); while (it.hasNext()) { Categoria c = it.next(); if (!c.getString("nombre").equals("COMPRAS")) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); float[] ingreso = calcularIngreso(c.getInteger("id"), anio); dataset.setValue(ingreso[0], c.getString("nombre"), "Enero"); dataset.setValue(ingreso[1], c.getString("nombre"), "Febrero"); dataset.setValue(ingreso[2], c.getString("nombre"), "Marzo"); dataset.setValue(ingreso[3], c.getString("nombre"), "Abril"); dataset.setValue(ingreso[4], c.getString("nombre"), "Mayo"); dataset.setValue(ingreso[5], c.getString("nombre"), "Junio"); dataset.setValue(ingreso[6], c.getString("nombre"), "Julio"); dataset.setValue(ingreso[7], c.getString("nombre"), "Agosto"); dataset.setValue(ingreso[8], c.getString("nombre"), "Septiembre"); dataset.setValue(ingreso[9], c.getString("nombre"), "Octubre"); dataset.setValue(ingreso[10], c.getString("nombre"), "Noviembre"); dataset.setValue(ingreso[11], c.getString("nombre"), "Diciembre"); JFreeChart chart = ChartFactory.createBarChart3D( "Ingresos en la categoria " + c.getString("nombre"), "mes", "Pesos", dataset, PlotOrientation.VERTICAL, true, true, false); // Creacin del panel con el grfico ChartPanel panelGrafico = new ChartPanel(chart); CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); org.jfree.chart.axis.CategoryAxis categoryaxis = categoryplot.getDomainAxis(); categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.2D)); CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer(); categoryitemrenderer.setBaseItemLabelsVisible(true); JPanel panelParaGrafico = new JPanel(); panelParaGrafico.setLayout(new BorderLayout()); panelGrande.add(panelParaGrafico); panelParaGrafico.add(panelGrafico); } } this.pack(); this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
From source file:net.sourceforge.jasa.view.OrderBookView.java
@Override public JComponent getComponent() { JPanel result = new JPanel(); result.setLayout(new BorderLayout()); result.add(this, BorderLayout.CENTER); return result; }