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:org.apache.jmeter.protocol.http.gui.HTTPFileArgsPanel.java
private JScrollPane makeScrollPane(Component comp) { JScrollPane pane = new JScrollPane(comp); pane.setPreferredSize(pane.getMinimumSize()); return pane;//from w ww . j av a2 s. c om }
From source file:org.apache.jmeter.visualizers.ViewResultsFullVisualizer.java
private synchronized Component createLeftPanel() { SampleResult rootSampleResult = new SampleResult(); rootSampleResult.setSampleLabel("Root"); rootSampleResult.setSuccessful(true); root = new SearchableTreeNode(rootSampleResult, null); treeModel = new DefaultTreeModel(root); jTree = new JTree(treeModel); jTree.setCellRenderer(new ResultsNodeRenderer()); jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jTree.addTreeSelectionListener(this); jTree.setRootVisible(false);//ww w . j a va 2s. c o m jTree.setShowsRootHandles(true); JScrollPane treePane = new JScrollPane(jTree); treePane.setPreferredSize(new Dimension(200, 300)); VerticalPanel leftPane = new VerticalPanel(); leftPane.add(treePane, BorderLayout.CENTER); leftPane.add(createComboRender(), BorderLayout.NORTH); autoScrollCB = new JCheckBox(JMeterUtils.getResString("view_results_autoscroll")); // $NON-NLS-1$ autoScrollCB.setSelected(false); autoScrollCB.addItemListener(this); leftPane.add(autoScrollCB, BorderLayout.SOUTH); return leftPane; }
From source file:org.cagrid.installer.steps.PresentLicenseStep.java
public void init(WizardModel m) { this.model = (CaGridInstallerModel) m; setLayout(new BorderLayout()); setSize(new Dimension(475, 161)); JPanel licensePanel = new JPanel(); licensePanel.setBackground(Color.WHITE); JTextPane textPane = new JTextPane(); licensePanel.add(textPane);//w w w.j av a2 s. com JScrollPane scrollPane = new JScrollPane(licensePanel); scrollPane.setPreferredSize(new Dimension(475, 150)); add(scrollPane, BorderLayout.CENTER); try { StringBuilder sb = new StringBuilder(); BufferedReader r = new BufferedReader( new InputStreamReader(getClass().getResourceAsStream("/cagrid_license.txt"))); String line = null; while ((line = r.readLine()) != null) { sb.append(line).append("\n"); } textPane.setText(sb.toString()); textPane.setFont(textPane.getFont().deriveFont((float) 10)); } catch (Exception ex) { String msg = "Error loading license: " + ex.getMessage(); logger.error(msg, ex); JOptionPane.showMessageDialog(null, msg, this.model.getMessage("error"), JOptionPane.ERROR_MESSAGE); } JPanel controlPanel = new JPanel(); controlPanel.setLayout(new GridBagLayout()); add(controlPanel, BorderLayout.SOUTH); JLabel label = new JLabel(this.model.getMessage("accept.license")); controlPanel.add(label); JCheckBox checkBox = new JCheckBox(); checkBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { PresentLicenseStep.this.setComplete(evt.getStateChange() == ItemEvent.SELECTED); } }); controlPanel.add(checkBox); }
From source file:org.cloudml.ui.graph.Visu.java
public void createFrame() { final VisualizationViewer<Vertex, Edge> vv = v.getVisualisationViewer(); vv.getRenderContext().setVertexIconTransformer(new Transformer<Vertex, Icon>() { public Icon transform(final Vertex v) { return new Icon() { public int getIconHeight() { return 40; }// w w w . j a v a 2s .co m public int getIconWidth() { return 40; } public void paintIcon(java.awt.Component c, Graphics g, int x, int y) { ImageIcon img; if (v.getType() == "node") { img = new ImageIcon(this.getClass().getResource("/server.png")); } else if (v.getType() == "platform") { img = new ImageIcon(this.getClass().getResource("/dbms.png")); } else { img = new ImageIcon(this.getClass().getResource("/soft.png")); } ImageObserver io = new ImageObserver() { public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { // TODO Auto-generated method stub return false; } }; g.drawImage(img.getImage(), x, y, getIconHeight(), getIconWidth(), io); if (!vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.black); } else { g.setColor(Color.red); properties.setModel(new CPIMTable(v)); runtimeProperties.setModel(new CPSMTable(v)); } g.drawString(v.getName(), x - 10, y + 50); } }; } }); // create a frame to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton save = new JButton("save"); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(frame, "save"); File result = fc.getSelectedFile(); JsonCodec codec = new JsonCodec(); OutputStream streamResult; try { streamResult = new FileOutputStream(result); codec.save(dmodel, streamResult); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); JButton saveImage = new JButton("save as image"); saveImage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(frame, "save"); File result = fc.getSelectedFile(); JsonCodec codec = new JsonCodec(); v.writeJPEGImage(result); } }); //WE NEED TO UPDATE THE FACADE AND THE GUI JButton load = new JButton("load"); load.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); int returnVal = fc.showDialog(frame, "load"); File result = fc.getSelectedFile(); JsonCodec codec = new JsonCodec(); try { InputStream stream = new FileInputStream(result); Deployment model = (Deployment) codec.load(stream); dmodel = model; v.setDeploymentModel(dmodel); ArrayList<Vertex> V = v.drawFromDeploymentModel(); nodeTypes.removeAll(); nodeTypes.setModel(fillList()); properties.setModel(new CPIMTable(V.get(0))); runtimeProperties.setModel(new CPSMTable(V.get(0))); CommandFactory fcommand = new CommandFactory(); CloudMlCommand load = fcommand.loadDeployment(result.getPath()); cml.fireAndWait(load); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton deploy = new JButton("Deploy!"); deploy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //cad.deploy(dmodel); System.out.println("deploy"); CommandFactory fcommand = new CommandFactory(); CloudMlCommand deploy = fcommand.deploy(); cml.fireAndWait(deploy); } }); //right panel JPanel intermediary = new JPanel(); intermediary.setLayout(new BoxLayout(intermediary, BoxLayout.PAGE_AXIS)); intermediary.setBorder(BorderFactory.createLineBorder(Color.black)); JLabel jlCPIM = new JLabel(); jlCPIM.setText("CPIM"); JLabel jlCPSM = new JLabel(); jlCPSM.setText("CPSM"); properties = new JTable(null); //properties.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); JTableHeader h = properties.getTableHeader(); JPanel props = new JPanel(); props.setLayout(new BorderLayout()); props.add(new JScrollPane(properties), BorderLayout.CENTER); props.add(h, BorderLayout.NORTH); runtimeProperties = new JTable(null); //runtimeProperties.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); JTableHeader h2 = runtimeProperties.getTableHeader(); JPanel runProps = new JPanel(); runProps.setLayout(new BorderLayout()); runProps.add(h2, BorderLayout.NORTH); runProps.add(new JScrollPane(runtimeProperties), BorderLayout.CENTER); intermediary.add(jlCPIM); intermediary.add(props); intermediary.add(jlCPSM); intermediary.add(runProps); content.add(intermediary, BorderLayout.EAST); //Left panel JPanel selection = new JPanel(); JLabel nodes = new JLabel(); nodes.setText("Types"); selection.setLayout(new BoxLayout(selection, BoxLayout.PAGE_AXIS)); nodeTypes = new JList(fillList()); nodeTypes.setLayoutOrientation(JList.VERTICAL); nodeTypes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); nodeTypes.setVisibleRowCount(10); JScrollPane types = new JScrollPane(nodeTypes); types.setPreferredSize(new Dimension(150, 80)); selection.add(nodes); selection.add(types); content.add(selection, BorderLayout.WEST); ((DefaultModalGraphMouse<Integer, Number>) gm) .add(new MyEditingGraphMousePlugin(0, vv, v.getGraph(), nodeTypes, dmodel)); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(save); controls.add(saveImage); controls.add(load); controls.add(deploy); controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox()); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:org.docx4all.swing.ExternalHyperlinkDialog.java
private void fillRow5(JPanel host, GridBagConstraints c) { c.gridx = 0;//from w w w .j a v a 2 s . c om c.gridy = 4; c.gridwidth = 2; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; c.insets = gridCellInsets; c.ipadx = 0; c.ipady = 0; c.anchor = GridBagConstraints.FIRST_LINE_START; c.fill = GridBagConstraints.NONE; JPanel directoryPathPanel = new JPanel(); directoryPathPanel.setBorder(BorderFactory.createEtchedBorder()); this.directoryPathField = new JTextArea(); this.directoryPathField.setEditable(false); this.directoryPathField.setEnabled(false); this.directoryPathField.setLineWrap(true); JScrollPane sp = new JScrollPane(this.directoryPathField); sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); sp.setMinimumSize(new Dimension(350, 100)); sp.setPreferredSize(new Dimension(350, 100)); directoryPathPanel.add(sp); host.add(directoryPathPanel, c); c.gridx = 2; c.gridy = 4; c.gridwidth = 1; c.gridheight = 1; c.weightx = 1.0; c.weighty = 1.0; c.insets = gridCellInsets; c.ipadx = 0; c.ipady = 0; c.anchor = GridBagConstraints.FIRST_LINE_START; c.fill = GridBagConstraints.NONE; this.selectButton = new JButton("Select..."); this.selectButton.addActionListener(new SelectButtonActionListener()); this.selectButton.setSize(100, 50); host.add(this.selectButton, c); }
From source file:org.drugis.addis.gui.wizard.AddStudyWizard.java
private static JComponent buildTip(String tip) { JTextPane area = new JTextPane(); StyledDocument doc = area.getStyledDocument(); addStylesToDoc(doc);//from ww w . j a v a 2 s.c o m area.setBackground(new Color(255, 180, 180)); try { doc.insertString(0, "x", doc.getStyle("tip")); doc.insertString(doc.getLength(), " Tip: \n", doc.getStyle("bold")); doc.insertString(doc.getLength(), tip, doc.getStyle("regular")); } catch (BadLocationException e) { e.printStackTrace(); } area.setEditable(false); JScrollPane pane = new JScrollPane(area); pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); pane.setPreferredSize(TextComponentFactory.textPaneDimension(area, 270, 70)); pane.setWheelScrollingEnabled(true); pane.getVerticalScrollBar().setValue(0); return pane; }
From source file:org.executequery.gui.browser.FindAction.java
private void init() { searchPanel = new JPanel(new GridBagLayout()); popup = new JPopupMenu(); searchField = WidgetFactory.createTextField(); searchField.setPreferredSize(new Dimension(270, 22)); resultsList = initSearchResultsList(); JScrollPane scrollPane = new JScrollPane(resultsList); scrollPane.setPreferredSize(new Dimension(300, 150)); JLabel label = new JLabel(" Search: "); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0;/* w w w. ja v a 2 s . c om*/ gbc.gridy = 0; gbc.insets.left = 3; gbc.insets.top = 3; gbc.insets.bottom = 3; searchPanel.add(label, gbc); gbc.gridx = 1; gbc.insets.right = 3; gbc.insets.left = 0; gbc.fill = GridBagConstraints.HORIZONTAL; searchPanel.add(searchField, gbc); gbc.gridx = 0; gbc.gridy++; gbc.gridwidth = 2; gbc.insets.left = 3; gbc.insets.top = 0; gbc.fill = GridBagConstraints.BOTH; searchPanel.add(scrollPane, gbc); popup.setBorder(BorderFactory.createLineBorder(UIUtils.getDefaultBorderColour())); popup.add(searchPanel); // when the window containing the "comp" has registered Esc key // then on pressing Esc instead of search popup getting closed // the event is sent to the window. to overcome this we // register an action for Esc. searchField.registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { popup.setVisible(false); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED); }
From source file:org.formic.wizard.step.gui.FeatureListStep.java
/** * {@inheritDoc}/* w ww . ja v a 2s . c o m*/ * @see org.formic.wizard.step.GuiStep#init() */ public Component init() { featureInfo = new JEditorPane("text/html", StringUtils.EMPTY); featureInfo.setEditable(false); featureInfo.addHyperlinkListener(new HyperlinkListener()); Feature[] features = provider.getFeatures(); JTable table = new JTable(features.length, 1) { private static final long serialVersionUID = 1L; public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); } public boolean isCellEditable(int row, int column) { return false; } }; table.setBackground(new javax.swing.JList().getBackground()); GuiForm form = createForm(); for (int ii = 0; ii < features.length; ii++) { final Feature feature = (Feature) features[ii]; final JCheckBox box = new JCheckBox(); String name = getName() + '.' + feature.getKey(); form.bind(name, box); box.putClientProperty("feature", feature); featureMap.put(feature.getKey(), box); if (feature.getInfo() == null) { feature.setInfo(Installer.getString(getName() + "." + feature.getKey() + ".html")); } feature.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (Feature.ENABLED_PROPERTY.equals(event.getPropertyName())) { if (box.isSelected() != feature.isEnabled()) { box.setSelected(feature.isEnabled()); } } } }); box.setText(Installer.getString(name)); box.setBackground(table.getBackground()); if (!feature.isAvailable()) { box.setSelected(false); box.setEnabled(false); } table.setValueAt(box, ii, 0); } FeatureListMouseListener mouseListener = new FeatureListMouseListener(); for (int ii = 0; ii < features.length; ii++) { Feature feature = (Feature) features[ii]; if (feature.isEnabled() && feature.isAvailable()) { JCheckBox box = (JCheckBox) featureMap.get(feature.getKey()); box.setSelected(true); mouseListener.processDependencies(feature); mouseListener.processExclusives(feature); } } table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.setDefaultRenderer(JCheckBox.class, new ComponentTableCellRenderer()); table.addKeyListener(new FeatureListKeyListener()); table.addMouseListener(mouseListener); table.getSelectionModel().addListSelectionListener(new FeatureListSelectionListener(table)); table.setRowSelectionInterval(0, 0); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JPanel container = new JPanel(new BorderLayout()); container.add(table, BorderLayout.CENTER); panel.add(new JScrollPane(container), BorderLayout.CENTER); JScrollPane infoScroll = new JScrollPane(featureInfo); infoScroll.setMinimumSize(new Dimension(0, 50)); infoScroll.setMaximumSize(new Dimension(0, 50)); infoScroll.setPreferredSize(new Dimension(0, 50)); panel.add(infoScroll, BorderLayout.SOUTH); return panel; }
From source file:org.genedb.jogra.plugins.TermRationaliser.java
/** * Return a new JFrame which is the main interface to the Rationaliser. *///from w w w .j av a 2 s . c o m public JFrame getMainPanel() { /* JFRAME */ frame.setTitle(WINDOW_TITLE); frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); frame.setLayout(new BorderLayout()); /* MENU */ JMenuBar menuBar = new JMenuBar(); JMenu actions_menu = new JMenu("Actions"); JMenuItem actions_mitem_1 = new JMenuItem("Refresh lists"); actions_mitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { initModels(); } }); actions_menu.add(actions_mitem_1); JMenu about_menu = new JMenu("About"); JMenuItem about_mitem_1 = new JMenuItem("About"); about_mitem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JOptionPane.showMessageDialog(null, "Term Rationaliser \n" + "Wellcome Trust Sanger Institute, UK \n" + "2009", "Term Rationaliser", JOptionPane.PLAIN_MESSAGE); } }); about_menu.add(about_mitem_1); menuBar.add(about_menu); menuBar.add(actions_menu); frame.add(menuBar, BorderLayout.NORTH); /* MAIN BOX */ Box center = Box.createHorizontalBox(); //A box that displays contents from left to right center.add(Box.createHorizontalStrut(5)); //Invisible fixed-width component /* FROM LIST AND PANEL */ fromList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //Allow multiple products to be selected fromList.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) { synchroniseLists(fromList, toList); //synchronise from left to right } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyTyped(KeyEvent arg0) { } }); Box fromPanel = this.createRationaliserPanel(FROM_LIST_NAME, fromList); //Box on left hand side fromPanel.add(Box.createVerticalStrut(55)); //Add some space center.add(fromPanel); //Add to main box center.add(Box.createHorizontalStrut(3)); //Add some space /* MIDDLE PANE */ Box middlePane = Box.createVerticalBox(); ClassLoader classLoader = this.getClass().getClassLoader(); //Needed to access the images later on ImageIcon leftButtonIcon = new ImageIcon(classLoader.getResource("left_arrow.gif")); ImageIcon rightButtonIcon = new ImageIcon(classLoader.getResource("right_arrow.gif")); leftButtonIcon = new ImageIcon(leftButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon! rightButtonIcon = new ImageIcon(rightButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon! JButton rightSynch = new JButton(rightButtonIcon); rightSynch.setToolTipText("Synchronise TO list. \n Shortcut: Right-arrow key"); rightSynch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { synchroniseLists(fromList, toList); } }); JButton leftSynch = new JButton(leftButtonIcon); leftSynch.setToolTipText("Synchronise FROM list. \n Shortcut: Left-arrow key"); leftSynch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { synchroniseLists(toList, fromList); } }); middlePane.add(rightSynch); middlePane.add(leftSynch); center.add(middlePane); //Add middle pane to main box center.add(Box.createHorizontalStrut(3)); /* TO LIST AND PANEL */ toList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //Single product selection in TO list toList.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_LEFT) { synchroniseLists(toList, fromList); //synchronise from right to left } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyTyped(KeyEvent arg0) { } }); Box toPanel = this.createRationaliserPanel(TO_LIST_NAME, toList); Box newTerm = Box.createVerticalBox(); textField = new JTextArea(1, 1); //textfield to let the user edit the name of an existing term textField.setMaximumSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().height, 10)); textField.setForeground(Color.BLUE); JScrollPane jsp = new JScrollPane(textField); //scroll pane so that there is a horizontal scrollbar jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); newTerm.add(jsp); TitledBorder editBorder = BorderFactory.createTitledBorder("Edit term name"); editBorder.setTitleColor(Color.DARK_GRAY); newTerm.setBorder(editBorder); toPanel.add(newTerm); //add textfield to panel center.add(toPanel); //add panel to main box center.add(Box.createHorizontalStrut(5)); frame.add(center); //add the main panel to the frame initModels(); //load the lists with data /* BOTTOM HALF OF FRAME */ Box main = Box.createVerticalBox(); TitledBorder border = BorderFactory.createTitledBorder("Information"); border.setTitleColor(Color.DARK_GRAY); /* INFORMATION BOX */ Box info = Box.createVerticalBox(); Box scope = Box.createHorizontalBox(); scope.add(Box.createHorizontalStrut(5)); scope.add(scopeLabel); //label showing the scope of the terms scope.add(Box.createHorizontalGlue()); Box productCount = Box.createHorizontalBox(); productCount.add(Box.createHorizontalStrut(5)); productCount.add(productCountLabel); //display the label showing the number of terms productCount.add(Box.createHorizontalGlue()); info.add(scope); info.add(productCount); info.setBorder(border); /* ACTION BUTTONS */ Box actionButtons = Box.createHorizontalBox(); actionButtons.add(Box.createHorizontalGlue()); actionButtons.add(Box.createHorizontalStrut(10)); JButton findFix = new JButton(new FindClosestMatchAction()); actionButtons.add(findFix); actionButtons.add(Box.createHorizontalStrut(10)); RationaliserAction ra = new RationaliserAction(); // RationaliserAction2 ra2 = new RationaliserAction2(); JButton go = new JButton(ra); actionButtons.add(go); actionButtons.add(Box.createHorizontalGlue()); /* MORE INFORMATION TOGGLE */ Box buttonBox = Box.createHorizontalBox(); final JButton toggle = new JButton("Hide information <<"); buttonBox.add(Box.createHorizontalStrut(5)); buttonBox.add(toggle); buttonBox.add(Box.createHorizontalGlue()); Box textBox = Box.createHorizontalBox(); final JScrollPane scrollPane = new JScrollPane(information); scrollPane.setPreferredSize(new Dimension(frame.getWidth(), 100)); scrollPane.setVisible(true); textBox.add(Box.createHorizontalStrut(5)); textBox.add(scrollPane); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (toggle.getText().equals("Show information >>")) { scrollPane.setVisible(true); toggle.setText("Hide information <<"); frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() + 100)); frame.pack(); } else if (toggle.getText().equals("Hide information <<")) { scrollPane.setVisible(false); toggle.setText("Show information >>"); frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() - 100)); frame.pack(); } } }; toggle.addActionListener(actionListener); main.add(Box.createVerticalStrut(5)); main.add(info); main.add(Box.createVerticalStrut(5)); main.add(Box.createVerticalStrut(5)); main.add(actionButtons); main.add(Box.createVerticalStrut(10)); main.add(buttonBox); main.add(textBox); frame.add(main, BorderLayout.SOUTH); frame.pack(); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setVisible(true); //initModels(); return frame; }
From source file:org.genedb.jogra.plugins.TermRationaliser.java
private Box createRationaliserPanel(final String name, final RationaliserJList rjlist) { int preferredHeight = 500; //change accordingly int preferredWidth = 500; Toolkit tk = Toolkit.getDefaultToolkit(); Dimension size = tk.getScreenSize(); int textboxHeight = 10; //change accordingly int textboxWidth = size.width; Box box = Box.createVerticalBox(); box.add(new JLabel(name)); JTextField searchField = new JTextField(20); //Search field on top /* We don't want this textfield's height to expand when * the Rationaliser is dragged to exapnd. So we set it's * height to what we want and the width to the width of * the screen //from w ww.j a v a2 s .c o m */ searchField.setMaximumSize(new Dimension(textboxWidth, textboxHeight)); rjlist.installJTextField(searchField); box.add(searchField); JScrollPane scrollPane = new JScrollPane(); //scroll pane scrollPane.setViewportView(rjlist); scrollPane.setPreferredSize(new Dimension(preferredWidth, preferredHeight)); box.add(scrollPane); TitledBorder sysidBorder = BorderFactory.createTitledBorder("Systematic IDs"); //systematic ID box sysidBorder.setTitleColor(Color.DARK_GRAY); final JTextArea idField = new JTextArea(1, 1); idField.setMaximumSize(new Dimension(textboxWidth, textboxHeight)); idField.setEditable(false); idField.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY)); idField.setForeground(Color.DARK_GRAY); JScrollPane scroll = new JScrollPane(idField); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); Box sysidBox = Box.createVerticalBox(); sysidBox.add(scroll /*idField*/); sysidBox.setBorder(sysidBorder); box.add(sysidBox); rjlist.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { Term highlightedTerm = (Term) rjlist.getSelectedValue(); if (highlightedTerm != null) { /* For each list, call the relevant methods * to get the systematic IDs. Then for the * right list, add the term name in the * text box below */ if (name.equals(FROM_LIST_NAME)) { idField.setText(StringUtils.collectionToCommaDelimitedString( termService.getSystematicIDs(highlightedTerm, selectedTaxons))); } else if (name.equals(TO_LIST_NAME)) { idField.setText(StringUtils.collectionToCommaDelimitedString( termService.getSystematicIDs(highlightedTerm, null))); /* We allow the user to edit the term name */ textField.setText(highlightedTerm.getName()); } } } }); return box; }