List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:serverrobot.DynamicGraph.java
public JPanel createPlatformActualPlot() { final TimeSeriesCollection dataset1 = createPlatformRollx2Collection(); final TimeSeriesCollection dataset2 = createPlatformPitchx2Collection(); final JFreeChart chart1 = createChart(dataset1, "Roll", -5, 5); final JFreeChart chart2 = createChart(dataset2, "Pitch", -5, 5); final ChartPanel chartPanel1 = new ChartPanel(chart1); final ChartPanel chartPanel2 = new ChartPanel(chart2); final JPanel panel = new JPanel(new BorderLayout()); final GridLayout grid = new GridLayout(2, 1); panel.setLayout(grid); panel.add(chartPanel1);/* ww w.j a v a 2s . c om*/ panel.add(chartPanel2); panel.setPreferredSize(new Dimension(1200, 600)); return panel; }
From source file:serverrobot.DynamicGraph.java
public JPanel createPlatformPlot() { final TimeSeriesCollection dataset1 = createPlatformRollCollection(); final TimeSeriesCollection dataset2 = createPlatformPitchCollection(); final JFreeChart chart1 = createChart(dataset1, "Roll", -5, 5); final JFreeChart chart2 = createChart(dataset2, "Pitch", -5, 5); final ChartPanel chartPanel1 = new ChartPanel(chart1); final ChartPanel chartPanel2 = new ChartPanel(chart2); final JPanel panel = new JPanel(new BorderLayout()); final GridLayout grid = new GridLayout(2, 1); panel.setLayout(grid); panel.add(chartPanel1);/*w ww.j a v a2 s . c o m*/ panel.add(chartPanel2); panel.setPreferredSize(new Dimension(1200, 600)); return panel; }
From source file:com.bsoft.baseframe.baseframe_utils.beanUtils.Classgenerator.java
/** * ???/*from ww w . j a v a 2s .c om*/ */ public Classgenerator() { setTitle("?"); setSize(WIDTH, HEIGHT); setLocationRelativeTo(null); JPanel panel = new JPanel(); panel.setLayout(new GridLayout(2, 1)); JPanel _beanPanel = new JPanel(); _beanPanel.setBorder(BorderFactory.createTitledBorder("?")); JPanel _otherPanel = new JPanel(); _otherPanel.setBorder(BorderFactory.createTitledBorder("?")); JLabel _tbLabel = new JLabel("??*"); _tb = new JTextField(25); _beanPanel.add(_tbLabel); _beanPanel.add(_tb); JLabel _stbbLabel = new JLabel("??*"); _stb = new JTextField(25); _beanPanel.add(_stbbLabel); _beanPanel.add(_stb); JLabel _ibatisLabel = new JLabel("IBTS*"); _ibatis = new JTextField(25); _beanPanel.add(_ibatisLabel); _beanPanel.add(_ibatis); JLabel _svLabel = new JLabel("SERVICE"); _sv = new JTextField(23); _otherPanel.add(_svLabel); _otherPanel.add(_sv); // JLabel _sviLabel = new JLabel("??*"); // _zwmc = new JTextField("?",25); // _zwmc.setEditable(false); // _otherPanel.add(_sviLabel); // _otherPanel.add(_zwmc); JLabel _detail = new JLabel("(?ServiceService??,"); JLabel _detail2 = new JLabel("??Service???.impl)"); _detail.setFont(new Font("", Font.ITALIC, 12)); _detail2.setFont(new Font("", Font.ITALIC, 12)); _otherPanel.add(_detail); _otherPanel.add(_detail2); panel.add(_beanPanel); panel.add(_otherPanel); add(panel, BorderLayout.CENTER); JPanel btnPanel = new JPanel(); JButton _saveBtn = new JButton("?"); _saveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int msg_code = clickSaveBtn(e); showMsg(msg_code); } }); JButton _restBtn = new JButton("?"); //? _restBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { _tb.setText(null); _stb.setText(null); _ibatis.setText(null); _sv.setText(null); // _svi.setText(null); } }); btnPanel.add(_saveBtn); btnPanel.add(_restBtn); add(btnPanel, BorderLayout.SOUTH); }
From source file:Visuals.RingChart.java
public JPanel addDefenceCharts() { lowValue = "Low (" + low + ")"; ChartPanel ringPanel = drawRingChart(); ringPanel.setDomainZoomable(true);/*from w w w .j a va2 s . c o m*/ JPanel thisRingPanel = new JPanel(); thisRingPanel.setLayout(new BorderLayout()); String[][] finalRisks = new String[riskCount][4]; for (int i = 0; i < riskCount; i++) { finalRisks[i][0] = risks[i][0]; finalRisks[i][1] = risks[i][1]; finalRisks[i][2] = risks[i][2]; finalRisks[i][3] = risks[i][3]; } JTable table = new JTable(finalRisks, networkDefenceColumns); TableColumn tcol = table.getColumnModel().getColumn(2); table.removeColumn(tcol); table.setEnabled(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); int width = 0; for (int row = 0; row < table.getRowCount(); row++) { TableCellRenderer renderer = table.getCellRenderer(row, 1); Component comp = table.prepareRenderer(renderer, row, 1); width = Math.max(comp.getPreferredSize().width, width); } table.getColumnModel().getColumn(1).setPreferredWidth(width); width = 0; for (int row = 0; row < table.getRowCount(); row++) { TableCellRenderer renderer = table.getCellRenderer(row, 2); Component comp = table.prepareRenderer(renderer, row, 2); width = Math.max(comp.getPreferredSize().width, width); } table.getColumnModel().getColumn(2).setPreferredWidth(width); table.setShowHorizontalLines(true); table.setRowHeight(40); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = table.getPreferredSize(); tableScrollPane .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1))); JLabel right = new JLabel( " "); thisRingPanel.add(right, BorderLayout.EAST); thisRingPanel.add(ringPanel, BorderLayout.CENTER); thisRingPanel.add(tableScrollPane, BorderLayout.SOUTH); return thisRingPanel; }
From source file:org.usfirst.frc.team2084.neuralnetwork.RobotHeadingTest.java
/** * //from ww w. ja v a2s.com */ @Override public void run() { try { final DefaultValueDataset headingData = new DefaultValueDataset(0); final DefaultValueDataset desiredHeadingData = new DefaultValueDataset(0); final CompassPlot headingPlot = new CompassPlot(); headingPlot.addDataset(headingData); headingPlot.addDataset(desiredHeadingData); final JFreeChart headingChart = new JFreeChart("Heading", headingPlot); final XYSeries headingTimeSeries = new XYSeries("Heading"); final XYSeriesCollection headingTimeData = new XYSeriesCollection(); headingTimeData.addSeries(headingTimeSeries); final JFreeChart headingTimeChart = ChartFactory.createXYLineChart("Heading vs. Time", "Time", "Heading", headingTimeData, PlotOrientation.VERTICAL, true, true, false); final XYSeries errorTimeSeries = new XYSeries("Error"); final XYSeriesCollection errorTimeData = new XYSeriesCollection(); errorTimeData.addSeries(errorTimeSeries); final JFreeChart errorTimeChart = ChartFactory.createXYLineChart("Error vs. Time", "Time", "Error", errorTimeData, PlotOrientation.VERTICAL, true, true, false); SwingUtilities.invokeAndWait(() -> { final JFrame frame = new JFrame("Charts"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final Container content = frame.getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); final JPanel chartPanel = new JPanel(); chartPanel.setLayout(new GridLayout(2, 2)); content.add(chartPanel); final ChartPanel headingPanel = new ChartPanel(headingChart); chartPanel.add(headingPanel); final ChartPanel headingTimePanel = new ChartPanel(headingTimeChart); chartPanel.add(headingTimePanel); final ChartPanel errorTimePanel = new ChartPanel(errorTimeChart); chartPanel.add(errorTimePanel); final JPanel buttonPanel = new JPanel(); content.add(buttonPanel); final JButton startButton = new JButton("Start"); final JButton stopButton = new JButton("Stop"); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stop(); startButton.setEnabled(false); stopButton.setEnabled(true); start(headingData, desiredHeadingData, headingTimeSeries, errorTimeSeries); } }); buttonPanel.add(startButton); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stop(); startButton.setEnabled(true); stopButton.setEnabled(false); } }); stopButton.setEnabled(false); buttonPanel.add(stopButton); frame.pack(); frame.setVisible(true); }); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:serverrobot.DynamicGraph.java
public JPanel createPositionPlot() { final TimeSeriesCollection dataset1 = createXPositionCollection(); final TimeSeriesCollection dataset2 = createYPositionCollection(); final TimeSeriesCollection dataset3 = createZPositionCollection(); final JFreeChart chart1 = createChart(dataset1, "X", 0.5, 0.75); final JFreeChart chart2 = createChart(dataset2, "Y", -0.35, 0.2); final JFreeChart chart3 = createChart(dataset3, "Z", 0.5, 0.8); final ChartPanel chartPanel1 = new ChartPanel(chart1); final ChartPanel chartPanel2 = new ChartPanel(chart2); final ChartPanel chartPanel3 = new ChartPanel(chart3); final JPanel panel = new JPanel(new BorderLayout()); final GridLayout grid = new GridLayout(3, 1); panel.setLayout(grid); panel.add(chartPanel1);/*w w w. jav a2s . com*/ panel.add(chartPanel2); panel.add(chartPanel3); panel.setPreferredSize(new Dimension(1200, 900)); return panel; }
From source file:com.floreantpos.config.ui.AddPrinterDialog.java
@Override public void initUI() { setLayout(new BorderLayout(5, 5)); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new MigLayout("", "[][grow][]", "[][][][][grow]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ titlePanel = new TitlePanel(); titlePanel.setTitle("Printer Type:");//$NON-NLS-1$ add(titlePanel, BorderLayout.NORTH); JLabel lblName = new JLabel("Virtual Printer Name : "); //$NON-NLS-1$ centerPanel.add(lblName, "cell 0 0,alignx trailing"); //$NON-NLS-1$ tfName = new FixedLengthTextField(20); cbVirtualPrinter = new JComboBox(); List<VirtualPrinter> virtualPrinters = VirtualPrinterDAO.getInstance().findAll(); cbVirtualPrinter// w ww. j a v a 2 s .co m .setModel(new DefaultComboBoxModel<VirtualPrinter>(virtualPrinters.toArray(new VirtualPrinter[0]))); //centerPanel.add(cbVirtualPrinter, "cell 1 0,growx"); //$NON-NLS-1$ centerPanel.add(tfName, "cell 1 0,growx"); //$NON-NLS-1$ JButton btnNew = new JButton(Messages.getString("AddPrinterDialog.7")); //$NON-NLS-1$ btnNew.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doAddNewVirtualPrinter(); } }); //centerPanel.add(btnNew, "cell 2 0"); //$NON-NLS-1$ JLabel lblDevice = new JLabel(Messages.getString("AddPrinterDialog.9")); //$NON-NLS-1$ centerPanel.add(lblDevice, "cell 0 1,alignx trailing"); //$NON-NLS-1$ cbDevice = new JComboBox(); List printerServices = new ArrayList<>(); printerServices.add(DO_NOT_PRINT); PrintService[] lookupPrintServices = PrintServiceLookup.lookupPrintServices(null, null); //cbDevice.setModel(new DefaultComboBoxModel(PrintServiceLookup.lookupPrintServices(null, null))); cbDevice.addItem(null); for (int i = 0; i < lookupPrintServices.length; i++) { printerServices.add(lookupPrintServices[i]); } cbDevice.setModel(new ComboBoxModel(printerServices)); cbDevice.setRenderer(new PrintServiceComboRenderer()); centerPanel.add(cbDevice, "cell 1 1,growx"); //$NON-NLS-1$ chckbxDefault = new JCheckBox(Messages.getString("AddPrinterDialog.12")); //$NON-NLS-1$ centerPanel.add(chckbxDefault, "cell 1 2"); //$NON-NLS-1$ JSeparator separator = new JSeparator(); centerPanel.add(separator, "cell 0 3 3 1,growx,gapy 50px"); //$NON-NLS-1$ add(centerPanel, BorderLayout.CENTER); JPanel panel = new JPanel(); JButton btnOk = new JButton(Messages.getString("AddPrinterDialog.16")); //$NON-NLS-1$ btnOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doAddPrinter(); } }); panel.add(btnOk); JButton btnCancel = new JButton(Messages.getString("AddPrinterDialog.17")); //$NON-NLS-1$ btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setCanceled(true); dispose(); } }); panel.add(btnCancel); add(panel, BorderLayout.SOUTH); //$NON-NLS-1$ }
From source file:DesktopManagerDemo.java
public DesktopManagerDemo() { setTitle("Animated DesktopManager"); m_count = m_tencount = 0;//from w w w .j a v a 2 s. c o m JPanel innerListenerPanel = new JPanel(new GridLayout(15, 1)); JPanel listenerPanel = new JPanel(new BorderLayout()); m_dmEventCanvas = new DMEventCanvas(); m_lActivates = new JLabel("activateFrame"); m_lBegindrags = new JLabel("beginDraggingFrame"); m_lBeginresizes = new JLabel("beginResizingFrame"); m_lCloses = new JLabel("closeFrame"); m_lDeactivates = new JLabel("deactivateFrame"); m_lDeiconifies = new JLabel("deiconifyFrame"); m_lDrags = new JLabel("dragFrame"); m_lEnddrags = new JLabel("endDraggingFrame"); m_lEndresizes = new JLabel("endResizingFrame"); m_lIconifies = new JLabel("iconifyFrame"); m_lMaximizes = new JLabel("maximizeFrame"); m_lMinimizes = new JLabel("minimizeFrame"); m_lOpens = new JLabel("openFrame"); m_lResizes = new JLabel("resizeFrame"); m_lSetbounds = new JLabel("setBoundsForFrame"); innerListenerPanel.add(m_lActivates); innerListenerPanel.add(m_lBegindrags); innerListenerPanel.add(m_lBeginresizes); innerListenerPanel.add(m_lCloses); innerListenerPanel.add(m_lDeactivates); innerListenerPanel.add(m_lDeiconifies); innerListenerPanel.add(m_lDrags); innerListenerPanel.add(m_lEnddrags); innerListenerPanel.add(m_lEndresizes); innerListenerPanel.add(m_lIconifies); innerListenerPanel.add(m_lMaximizes); innerListenerPanel.add(m_lMinimizes); innerListenerPanel.add(m_lOpens); innerListenerPanel.add(m_lResizes); innerListenerPanel.add(m_lSetbounds); listenerPanel.add("Center", m_dmEventCanvas); listenerPanel.add("West", innerListenerPanel); listenerPanel.setOpaque(true); listenerPanel.setBackground(Color.white); m_myDesktopManager = new MyDesktopManager(); m_desktop = new JDesktopPane(); m_desktop.setDesktopManager(m_myDesktopManager); 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, 600); 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:ac.kaist.ccs.presentation.CCSHubSelectionCost.java
public CCSHubSelectionCost(final String title, Map<Integer, List<Double>> data) { super(title); this.title = title; final XYDataset dataset = createDataset(data); final JFreeChart chart = createChart(dataset); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BorderLayout()); JButton buttonExport = new JButton("Export"); buttonPanel.add("East", buttonExport); buttonExport.addActionListener(new ActionListener() { ChartPanel chartPanel;//from w w w .j av a 2 s .c om public ActionListener init(ChartPanel chartPanel) { this.chartPanel = chartPanel; return this; } @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub Dimension size = chartPanel.getSize(); try { //String outPath = textFieldSelectPath.getText(); //String filename = "chromatography.png"; //String path = outPath+"/"+filename; JFileChooser fileChooser = new JFileChooser(); fileChooser.setCurrentDirectory(new File("/Users/mac/Desktop")); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("JPEG", "jpeg")); int returnVal = fileChooser.showDialog(new JFrame(), "Open File Path"); if (returnVal == JFileChooser.APPROVE_OPTION) { String inputPath = fileChooser.getSelectedFile().getAbsolutePath(); if (!inputPath.endsWith(".jpeg")) inputPath = inputPath + ".jpeg"; OutputStream os = new FileOutputStream(inputPath); System.out.println(inputPath + "///" + size.width + " " + size.height); BufferedImage chartImage = chartPanel.getChart().createBufferedImage(size.width, size.height, null); ImageIO.write(chartImage, "png", os); os.close(); JOptionPane.showMessageDialog(null, "Chart image was saved in " + inputPath); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.init(chartPanel)); panel.add("Center", chartPanel); panel.add("South", buttonPanel); chartPanel.setPreferredSize(new java.awt.Dimension(700, 500)); setContentPane(panel); }
From source file:components.SharedModelDemo.java
public SharedModelDemo() { super(new BorderLayout()); Vector data = new Vector(7); String[] columnNames = { "French", "Spanish", "Italian" }; String[] oneData = { "un", "uno", "uno" }; String[] twoData = { "deux", "dos", "due" }; String[] threeData = { "trois", "tres", "tre" }; String[] fourData = { "quatre", "cuatro", "quattro" }; String[] fiveData = { "cinq", "cinco", "cinque" }; String[] sixData = { "six", "seis", "sei" }; String[] sevenData = { "sept", "siete", "sette" }; //Build the model. SharedDataModel dataModel = new SharedDataModel(columnNames); dataModel.addElement(oneData);/*from w w w .jav a 2s . c o m*/ dataModel.addElement(twoData); dataModel.addElement(threeData); dataModel.addElement(fourData); dataModel.addElement(fiveData); dataModel.addElement(sixData); dataModel.addElement(sevenData); list = new JList(dataModel); list.setCellRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList l, Object value, int i, boolean s, boolean f) { String[] array = (String[]) value; return super.getListCellRendererComponent(l, array[0], i, s, f); } }); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); JScrollPane listPane = new JScrollPane(list); table = new JTable(dataModel); table.setSelectionModel(listSelectionModel); JScrollPane tablePane = new JScrollPane(table); //Build control area (use default FlowLayout). JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2); comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); //Build output area. output = new JTextArea(10, 40); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); //Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.X_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); listContainer.setBorder(BorderFactory.createTitledBorder("List")); listContainer.add(listPane); JPanel tableContainer = new JPanel(new GridLayout(1, 1)); tableContainer.setBorder(BorderFactory.createTitledBorder("Table")); tableContainer.add(tablePane); tablePane.setPreferredSize(new Dimension(300, 100)); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(400, 50)); topHalf.setPreferredSize(new Dimension(400, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.NORTH); bottomHalf.add(outputPane, BorderLayout.CENTER); //XXX: next line needed if bottomHalf is a scroll pane: //bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 135)); splitPane.add(bottomHalf); }