List of usage examples for javax.swing JScrollPane setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:teambootje.A6.java
/** * Creates new form A6/* w ww . j av a2 s . com*/ */ public A6() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 6"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT Locatie.land, locatie.stad, count(persoon.LID) as Aantal FROM persoon, Locatie WHERE persoon.LID = locatie.LID GROUP BY stad"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String city = rs.getString("locatie.stad"); int amount = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String c1 = city; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(c1, a1); pieDataset.setValue("Rotterdam", new Integer(1)); pieDataset.setValue("Bergen op zoom", new Integer(1)); JFreeChart chart = ChartFactory.createPieChart3D("Waar komen bezoekers vandaan", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Waar komen bezoekers vandaan", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Land", "stad", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:teambootje.A3.java
/** * Creates new form A3//from www . j ava2 s . c om */ public A3() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 3"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT locatie.land, locatie.stad, COUNT(posts.PID) AS Aantal FROM persoon, locatie, posts WHERE persoon.LID = locatie.LID AND persoon.AID = posts.AID GROUP BY locatie.land ORDER BY count(posts.PID)"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String land = rs.getString("locatie.land"); String stad = rs.getString("locatie.stad"); int aantal = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String l1 = land; String s1 = stad; int a1 = aantal; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(s1, a1); JFreeChart chart = ChartFactory.createPieChart3D("Aantal Posts per locatie", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal Posts per locatie", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Land", "Stad", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:ContainerEventDemo.java
public ContainerEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); //Initialize an empty list of buttons. buttonList = new Vector(10, 10); //Create all the components. addButton = new JButton("Add a button"); addButton.setActionCommand(ADD);/* www . ja v a2 s . com*/ addButton.addActionListener(this); removeButton = new JButton("Remove a button"); removeButton.setActionCommand(REMOVE); removeButton.addActionListener(this); buttonPanel = new JPanel(new GridLayout(1, 1)); buttonPanel.setPreferredSize(new Dimension(200, 75)); buttonPanel.addContainerListener(this); display = new JTextArea(); display.setEditable(false); JScrollPane scrollPane = new JScrollPane(display); scrollPane.setPreferredSize(new Dimension(200, 75)); clearButton = new JButton("Clear text area"); clearButton.setActionCommand(CLEAR); clearButton.addActionListener(this); c.fill = GridBagConstraints.BOTH; //Fill entire cell. c.weighty = 1.0; //Button area and message area have equal height. c.gridwidth = GridBagConstraints.REMAINDER; //end of row gridbag.setConstraints(scrollPane, c); add(scrollPane); c.weighty = 0.0; gridbag.setConstraints(clearButton, c); add(clearButton); c.weightx = 1.0; //Add/remove buttons have equal width. c.gridwidth = 1; //NOT end of row gridbag.setConstraints(addButton, c); add(addButton); c.gridwidth = GridBagConstraints.REMAINDER; //end of row gridbag.setConstraints(removeButton, c); add(removeButton); c.weighty = 1.0; //Button area and message area have equal height. gridbag.setConstraints(buttonPanel, c); add(buttonPanel); setPreferredSize(new Dimension(400, 400)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:teambootje.A7.java
/** * Creates new form A7// w ww . j ava 2s . co m */ public A7() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 7"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT doelgroep.doelgroep, COUNT(*) AS Aantal FROM doelgroep GROUP BY doelgroep.doelgroep"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String ta = rs.getString("doelgroep.Doelgroep"); int amount = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String dd = ta; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(dd, a1); pieDataset.setValue("Bedrijfsleven", new Integer(1)); pieDataset.setValue("50+", new Integer(1)); pieDataset.setValue("40+", new Integer(1)); pieDataset.setValue("30+", new Integer(1)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal mensen per Doelgroep", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal mensen per Doelgroep", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Doelgroep", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:teambootje.A8.java
/** * Creates new form A8/*from w w w . java 2 s .co m*/ */ public A8() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 8"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT doelgroep.Doelgroep, COUNT(posts.post) AS Aantal FROM doelgroep, posts WHERE posts.DID = doelgroep.DID GROUP BY doelgroep.Doelgroep"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String ta = rs.getString("doelgroep.Doelgroep"); int amount = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String dd = ta; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(dd, a1); pieDataset.setValue("50+", new Integer(0)); pieDataset.setValue("Tiener", new Integer(0)); pieDataset.setValue("40+", new Integer(0)); pieDataset.setValue("30+", new Integer(0)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal Posts per doelgroep", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal Posts per doelgroep", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Doelgoep", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:de.huxhorn.lilith.swing.LicenseAgreementDialog.java
private void initUI() { JPanel content = new JPanel(); content.setLayout(new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); JTextPane licenseTextPane = new JTextPane(); HTMLEditorKit htmlEditorKit = new HTMLEditorKit(); String licenseText = null;/* www.j a v a 2 s . c o m*/ InputStream licenseStream = LicenseAgreementDialog.class.getResourceAsStream("/licenses/license.html"); if (licenseStream != null) { try { licenseText = IOUtils.toString(licenseStream, StandardCharsets.UTF_8); } catch (IOException ex) { if (logger.isErrorEnabled()) logger.error("Exception while loading license!", ex); IOUtilities.interruptIfNecessary(ex); } finally { IOUtilities.closeQuietly(licenseStream); } } if (licenseText == null) { if (logger.isErrorEnabled()) logger.error("Couldn't find license text! Exiting!"); System.exit(-1); } licenseTextPane.setEditorKit(htmlEditorKit); licenseTextPane.setEditable(false); licenseTextPane.setText(licenseText); JScrollPane licenseScrollPane = new JScrollPane(licenseTextPane); licenseScrollPane.setPreferredSize(new Dimension(640, 480)); content.add(licenseScrollPane, BorderLayout.CENTER); content.add(buttonPanel, BorderLayout.SOUTH); AcceptAction acceptAction = new AcceptAction(); DeclineAction declineAction = new DeclineAction(); JButton acceptButton = new JButton(acceptAction); JButton declineButton = new JButton(declineAction); buttonPanel.add(acceptButton); buttonPanel.add(declineButton); setContentPane(content); licenseTextPane.setCaretPosition(0); declineButton.requestFocusInWindow(); }
From source file:csh.vctt.launcher.Launcher.java
/** * Prompt the user to select their character from a dialog. * @return Unique id number of the selected character. *///ww w .j a v a2s. c om private String getPlayerSelection() { String selectedId = "-1"; String outfitMembersJson = DataManager.execQuery(DataManager.M_OUTFITMEMBER_SELECT_QUERY); List<Player> outfitMembers = DataManager.getOutfitMembers(outfitMembersJson); Object[] outfitMembersArrObj = outfitMembers.toArray(); Player[] outfitMembersArr = new Player[outfitMembersArrObj.length]; for (int i = 0; i < outfitMembersArrObj.length; i++) { outfitMembersArr[i] = (Player) outfitMembersArrObj[i]; } JList<Player> memSelList = new JList<Player>(outfitMembersArr); memSelList.setVisibleRowCount(10); JScrollPane memScrollPane = new JScrollPane(memSelList); memScrollPane.setPreferredSize(new Dimension(200, 400)); int userAction = JOptionPane.showConfirmDialog(null, memScrollPane, "Select Character and Press Ok", JOptionPane.PLAIN_MESSAGE); Player selectedPlayer = null; if (userAction == JOptionPane.YES_OPTION) { selectedPlayer = memSelList.getSelectedValue(); } if (selectedPlayer != null) { selectedId = selectedPlayer.getId(); } return selectedId; }
From source file:MouseEventDemo.java
public MouseEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0;/*from ww w.j a v a2 s . c o m*/ c.weighty = 1.0; c.insets = new Insets(1, 1, 1, 1); blankArea = new BlankArea(new Color(0.98f, 0.97f, 0.85f)); gridbag.setConstraints(blankArea, c); add(blankArea); c.insets = new Insets(0, 0, 0, 0); textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new Dimension(200, 75)); gridbag.setConstraints(scrollPane, c); add(scrollPane); //Register for mouse events on blankArea and the panel. blankArea.addMouseListener(this); addMouseListener(this); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:SwingMouseMotionEventDemo.java
public SwingMouseMotionEventDemo() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0;//w w w . ja va 2 s . c o m c.weighty = 1.0; c.insets = new Insets(1, 1, 1, 1); blankArea = new BlankArea(new Color(0.98f, 0.97f, 0.85f)); gridbag.setConstraints(blankArea, c); add(blankArea); c.insets = new Insets(0, 0, 0, 0); textArea = new JTextArea(); textArea.setEditable(false); JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setPreferredSize(new Dimension(200, 75)); gridbag.setConstraints(scrollPane, c); add(scrollPane); //Register for mouse events on blankArea and panel. blankArea.addMouseMotionListener(this); addMouseMotionListener(this); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:MultiListener.java
public MultiListener() { super(new GridBagLayout()); GridBagLayout gridbag = (GridBagLayout) getLayout(); GridBagConstraints c = new GridBagConstraints(); JLabel l = null;//from w w w.ja v a2 s. c o m c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; l = new JLabel("What MultiListener hears:"); gridbag.setConstraints(l, c); add(l); c.weighty = 1.0; topTextArea = new JTextArea(); topTextArea.setEditable(false); JScrollPane topScrollPane = new JScrollPane(topTextArea); Dimension preferredSize = new Dimension(200, 75); topScrollPane.setPreferredSize(preferredSize); gridbag.setConstraints(topScrollPane, c); add(topScrollPane); c.weightx = 0.0; c.weighty = 0.0; l = new JLabel("What Eavesdropper hears:"); gridbag.setConstraints(l, c); add(l); c.weighty = 1.0; bottomTextArea = new JTextArea(); bottomTextArea.setEditable(false); JScrollPane bottomScrollPane = new JScrollPane(bottomTextArea); bottomScrollPane.setPreferredSize(preferredSize); gridbag.setConstraints(bottomScrollPane, c); add(bottomScrollPane); c.weightx = 1.0; c.weighty = 0.0; c.gridwidth = 1; c.insets = new Insets(10, 10, 0, 10); button1 = new JButton("Blah blah blah"); gridbag.setConstraints(button1, c); add(button1); c.gridwidth = GridBagConstraints.REMAINDER; button2 = new JButton("You don't say!"); gridbag.setConstraints(button2, c); add(button2); button1.addActionListener(this); button2.addActionListener(this); button2.addActionListener(new Eavesdropper(bottomTextArea)); setPreferredSize(new Dimension(450, 450)); setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 1, 2, 2, Color.black), BorderFactory.createEmptyBorder(5, 5, 5, 5))); }