List of usage examples for javax.swing JScrollPane getPreferredSize
@Transient
public Dimension getPreferredSize()
preferredSize
has been set to a non-null
value just returns it. From source file:gdt.jgui.entity.query.JQueryPanel.java
/** * The default constructor./*from w w w . j a v a 2s. c o m*/ */ public JQueryPanel() { GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 100, 0, 0 }; gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0 }; gridBagLayout.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0 }; setLayout(gridBagLayout); JLabel lblElement = new JLabel("Element"); GridBagConstraints gbc_lblElement = new GridBagConstraints(); gbc_lblElement.insets = new Insets(5, 5, 5, 5); gbc_lblElement.gridx = 0; gbc_lblElement.gridy = 0; gbc_lblElement.anchor = GridBagConstraints.FIRST_LINE_START; add(lblElement, gbc_lblElement); elementComboBox = new JComboBox<String>(); GridBagConstraints gbc_elementComboBox = new GridBagConstraints(); gbc_elementComboBox.fill = GridBagConstraints.HORIZONTAL; gbc_elementComboBox.insets = new Insets(0, 0, 5, 0); gbc_elementComboBox.gridx = 1; gbc_elementComboBox.gridy = 0; gbc_elementComboBox.anchor = GridBagConstraints.FIRST_LINE_START; add(elementComboBox, gbc_elementComboBox); elementComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { try { initItemNameSelector(); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); JLabel lblItemNameField = new JLabel("Item field"); GridBagConstraints gbc_lblItemField = new GridBagConstraints(); gbc_lblItemField.insets = new Insets(5, 5, 5, 5); gbc_lblItemField.gridx = 0; gbc_lblItemField.gridy = 1; gbc_lblItemField.anchor = GridBagConstraints.FIRST_LINE_START; add(lblItemNameField, gbc_lblItemField); itemNameFieldComboBox = new JComboBox<String>(); GridBagConstraints gbc_itemNameFieldComboBox = new GridBagConstraints(); gbc_itemNameFieldComboBox.insets = new Insets(0, 0, 5, 0); gbc_itemNameFieldComboBox.fill = GridBagConstraints.HORIZONTAL; gbc_itemNameFieldComboBox.gridx = 1; gbc_itemNameFieldComboBox.gridy = 1; gbc_itemNameFieldComboBox.anchor = GridBagConstraints.FIRST_LINE_START; add(itemNameFieldComboBox, gbc_itemNameFieldComboBox); itemNameFieldComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { try { initItemNameSelector(); initItemValueSelector(); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); JLabel itemTitle = new JLabel("Item title"); GridBagConstraints gbc_lblItemtitle = new GridBagConstraints(); gbc_lblItemtitle.insets = new Insets(5, 5, 5, 5); gbc_lblItemtitle.gridx = 0; gbc_lblItemtitle.gridy = 2; gbc_lblItemtitle.anchor = GridBagConstraints.FIRST_LINE_START; add(itemTitle, gbc_lblItemtitle); itemNameComboBox = new JComboBox<String>(); GridBagConstraints gbc_itemComboBox = new GridBagConstraints(); gbc_itemComboBox.insets = new Insets(0, 0, 5, 0); gbc_itemComboBox.fill = GridBagConstraints.HORIZONTAL; gbc_itemComboBox.gridx = 1; gbc_itemComboBox.gridy = 2; gbc_itemComboBox.anchor = GridBagConstraints.FIRST_LINE_START; add(itemNameComboBox, gbc_itemComboBox); itemNameComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { try { initItemValueSelector(); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); JLabel itemValue = new JLabel("Item value"); GridBagConstraints gbc_lblItemValue = new GridBagConstraints(); gbc_lblItemValue.insets = new Insets(5, 5, 5, 5); gbc_lblItemValue.weighty = 0.0; gbc_lblItemValue.gridx = 0; gbc_lblItemValue.gridy = 3; gbc_lblItemValue.anchor = GridBagConstraints.FIRST_LINE_START; add(itemValue, gbc_lblItemValue); itemValueComboBox = new JComboBox<String>(); GridBagConstraints gbc_itemValueComboBox = new GridBagConstraints(); gbc_itemValueComboBox.insets = new Insets(0, 0, 5, 0); gbc_itemValueComboBox.fill = GridBagConstraints.HORIZONTAL; gbc_itemValueComboBox.gridx = 1; gbc_itemValueComboBox.gridy = 3; gbc_itemValueComboBox.anchor = GridBagConstraints.FIRST_LINE_START; add(itemValueComboBox, gbc_itemValueComboBox); table = new JTable(); JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent evt) { int row = table.rowAtPoint(evt.getPoint()); int col = table.columnAtPoint(evt.getPoint()); System.out.println("JQueryPanel:cell click:row=" + row + " column=" + col); if (col == 1) { String label$ = (String) table.getValueAt(row, 1); System.out.println("JQueryPanel:cell click:label=" + label$); Entigrator entigrator = console.getEntigrator(entihome$); String entity$ = entigrator.indx_keyAtLabel(label$); JEntityFacetPanel efp = new JEntityFacetPanel(); String efpLocator$ = efp.getLocator(); efpLocator$ = Locator.append(efpLocator$, Entigrator.ENTIHOME, entihome$); efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_KEY, entity$); JConsoleHandler.execute(console, efpLocator$); } } }); GridBagConstraints gbc_scroll_panel = new GridBagConstraints(); gbc_scroll_panel.anchor = GridBagConstraints.NORTH; gbc_scroll_panel.gridwidth = 2; gbc_scroll_panel.weighty = 1.0; gbc_scroll_panel.fill = GridBagConstraints.HORIZONTAL; gbc_scroll_panel.gridx = 0; gbc_scroll_panel.gridy = 4; add(scrollPane, gbc_scroll_panel); scrollPane.setMinimumSize(scrollPane.getPreferredSize()); }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
/** * create the query builder UI./*from w ww .j av a 2 s. c o m*/ */ protected void createUI() { removeAll(); JMenuItem saveItem = new JMenuItem(UIRegistry.getResourceString("QB_SAVE")); Action saveActionListener = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (saveQuery(false)) { try { String selId = null; if (selectedQFP != null && selectedQFP.getQueryField() != null) { selId = selectedQFP.getQueryField().getStringId(); } final String selectedFldId = selId; setupUI(true); SwingUtilities.invokeLater(new Runnable() { /* (non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { if (selectedFldId != null) { for (QueryFieldPanel qfp : queryFieldItems) { if (qfp.getQueryField() != null && selectedFldId.equals(qfp.getQueryField().getStringId())) { selectQFP(qfp); return; } } selectQFP(queryFieldItems.get(0)); } } }); } catch (Exception ex) { } setSaveBtnEnabled(false); } } }; saveItem.addActionListener(saveActionListener); JMenuItem saveAsItem = new JMenuItem(UIRegistry.getResourceString("QB_SAVE_AS")); Action saveAsActionListener = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (saveQuery(true)) { setSaveBtnEnabled(false); } } }; saveAsItem.addActionListener(saveAsActionListener); JComponent[] itemSample = { saveItem, saveAsItem }; saveBtn = new DropDownButton(UIRegistry.getResourceString("QB_SAVE"), null, 1, java.util.Arrays.asList(itemSample)); saveBtn.addActionListener(saveActionListener); String ACTION_KEY = "SAVE"; KeyStroke ctrlS = KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); InputMap inputMap = saveBtn.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(ctrlS, ACTION_KEY); ActionMap actionMap = saveBtn.getActionMap(); actionMap.put(ACTION_KEY, saveActionListener); ACTION_KEY = "SAVE_AS"; KeyStroke ctrlA = KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); inputMap.put(ctrlA, ACTION_KEY); actionMap.put(ACTION_KEY, saveAsActionListener); saveBtn.setActionMap(actionMap); UIHelper.setControlSize(saveBtn); //saveBtn.setOverrideBorder(true, BasicBorders.getButtonBorder()); listBoxPanel = new JPanel(new HorzLayoutManager(2, 2)); Vector<TableQRI> list = new Vector<TableQRI>(); for (int k = 0; k < tableTree.getKids(); k++) { list.add(tableTree.getKid(k).getTableQRI()); } Collections.sort(list); DefaultListModel model = new DefaultListModel(); for (TableQRI qri : list) { model.addElement(qri); } tableList = new JList(model); QryListRenderer qr = new QryListRenderer(IconManager.IconSize.Std16); qr.setDisplayKidIndicator(false); tableList.setCellRenderer(qr); JScrollPane spt = new JScrollPane(tableList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); Dimension pSize = spt.getPreferredSize(); pSize.height = 200; spt.setPreferredSize(pSize); JPanel topPanel = new JPanel(new BorderLayout()); scrollPane = new JScrollPane(listBoxPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); tableList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int inx = tableList.getSelectedIndex(); if (inx > -1) { fillNextList(tableList); } else { listBoxPanel.removeAll(); } } } }); addBtn = new JButton(IconManager.getImage("PlusSign", IconManager.IconSize.Std16)); addBtn.setEnabled(false); addBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { BaseQRI qri = (BaseQRI) listBoxList.get(currentInx).getSelectedValue(); if (qri.isInUse) { return; } try { FieldQRI fieldQRI = buildFieldQRI(qri); if (fieldQRI == null) { throw new Exception("null FieldQRI"); } SpQueryField qf = new SpQueryField(); qf.initialize(); qf.setFieldName(fieldQRI.getFieldName()); qf.setStringId(fieldQRI.getStringId()); query.addReference(qf, "fields"); if (!isExportMapping) { addQueryFieldItem(fieldQRI, qf, false); } else { addNewMapping(fieldQRI, qf, null, false); } } catch (Exception ex) { log.error(ex); UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(QueryBldrPane.class, ex); return; } } }); contextPanel = new JPanel(new BorderLayout()); contextPanel.add(createLabel("Search Context", SwingConstants.CENTER), BorderLayout.NORTH); // I18N contextPanel.add(spt, BorderLayout.CENTER); contextPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); JPanel schemaPanel = new JPanel(new BorderLayout()); schemaPanel.add(scrollPane, BorderLayout.CENTER); topPanel.add(contextPanel, BorderLayout.WEST); topPanel.add(schemaPanel, BorderLayout.CENTER); add(topPanel, BorderLayout.NORTH); queryFieldsPanel = new JPanel(); queryFieldsPanel.setLayout(new NavBoxLayoutManager(0, 2)); queryFieldsScroll = new JScrollPane(queryFieldsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); queryFieldsScroll.setBorder(null); add(queryFieldsScroll); //if (!isExportMapping) //{ final JPanel mover = buildMoverPanel(false); add(mover, BorderLayout.EAST); // } String searchLbl = schemaMapping == null ? getResourceString("QB_SEARCH") : getResourceString("QB_EXPORT_PREVIEW"); searchBtn = createButton(searchLbl); searchBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { // int m = ae.getModifiers(); // boolean ors = (m & ActionEvent.ALT_MASK) > 0 && (m & ActionEvent.CTRL_MASK) > 0 && (m & ActionEvent.SHIFT_MASK) > 0; // if (ors) // { // System.out.println("Disjunctional conjoinment desire gesture detected"); // } // doSearch(ors); doSearch(false); } }); distinctChk = createCheckBox(UIRegistry.getResourceString("QB_DISTINCT")); distinctChk.setVisible(schemaMapping == null); if (schemaMapping == null) { distinctChk.setSelected(false); distinctChk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { new SwingWorker() { /* (non-Javadoc) * @see edu.ku.brc.helpers.SwingWorker#construct() */ @Override public Object construct() { if (distinctChk.isSelected()) { UsageTracker.incrUsageCount("QB.DistinctOn"); } else { UsageTracker.incrUsageCount("QB.DistinctOff"); } if ((isTreeLevelSelected() || isAggFieldSelected()) && countOnly && distinctChk.isSelected()) { countOnlyChk.setSelected(false); countOnly = false; } query.setCountOnly(countOnly); query.setSelectDistinct(distinctChk.isSelected()); setSaveBtnEnabled(thereAreItems()); return null; } }.start(); } }); } countOnlyChk = createCheckBox(UIRegistry.getResourceString("QB_COUNT_ONLY")); countOnlyChk.setSelected(false); countOnlyChk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { new SwingWorker() { /* (non-Javadoc) * @see edu.ku.brc.helpers.SwingWorker#construct() */ @Override public Object construct() { //Don't allow change while query is running. if (runningResults.get() == null) { countOnly = !countOnly; if (countOnly) { UsageTracker.incrUsageCount("QB.CountOnlyOn"); } else { UsageTracker.incrUsageCount("QB.CountOnlyOff"); } if ((isTreeLevelSelected() || isAggFieldSelected()) && countOnly && (distinctChk.isSelected() || searchSynonymyChk.isSelected())) { distinctChk.setSelected(false); searchSynonymyChk.setSelected(false); } } else { //This might be awkward and/or klunky... countOnlyChk.setSelected(countOnly); } query.setCountOnly(countOnly); query.setSelectDistinct(distinctChk.isSelected()); setSaveBtnEnabled(thereAreItems()); return null; } }.start(); } }); searchSynonymyChk = createCheckBox(UIRegistry.getResourceString("QB_SRCH_SYNONYMS")); searchSynonymyChk.setSelected(searchSynonymy); searchSynonymyChk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { new SwingWorker() { /* (non-Javadoc) * @see edu.ku.brc.helpers.SwingWorker#construct() */ @Override public Object construct() { searchSynonymy = !searchSynonymy; if (!searchSynonymy) { UsageTracker.incrUsageCount("QB.SearchSynonymyOff"); } else { UsageTracker.incrUsageCount("QB.SearchSynonymyOn"); } if (isTreeLevelSelected() && countOnly && searchSynonymyChk.isSelected()) { countOnlyChk.setSelected(false); countOnly = false; } query.setSearchSynonymy(searchSynonymy); setSaveBtnEnabled(thereAreItems()); return null; } }.start(); } }); smushedChk = createCheckBox(UIRegistry.getResourceString("QB_SMUSH_RESULTS")); smushedChk.setVisible(isSmushableContext()); if (isSmushableContext()) { smushedChk.setSelected(smushed); smushedChk.setToolTipText( String.format(UIRegistry.getResourceString("QB_SMUSH_RESULTS_HINT"), getCatalogNumberTitle())); smushedChk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { new SwingWorker() { /* * (non-Javadoc) * * @see edu.ku.brc.helpers.SwingWorker#construct() */ @Override public Object construct() { smushed = !smushed; if (!smushed) { UsageTracker.incrUsageCount("QB.SmushedOff"); } else { UsageTracker.incrUsageCount("QB.SmushedOn"); } query.setSmushed(smushed); setSaveBtnEnabled(thereAreItems()); return null; } }.start(); } }); } PanelBuilder outer = new PanelBuilder( new FormLayout("p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 6dlu, p", "p")); CellConstraints cc = new CellConstraints(); outer.add(smushedChk, cc.xy(1, 1)); outer.add(searchSynonymyChk, cc.xy(3, 1)); outer.add(distinctChk, cc.xy(5, 1)); outer.add(countOnlyChk, cc.xy(7, 1)); outer.add(searchBtn, cc.xy(9, 1)); outer.add(saveBtn, cc.xy(11, 1)); JPanel bottom = new JPanel(new BorderLayout()); bottom.add(outer.getPanel(), BorderLayout.EAST); JButton helpBtn = UIHelper.createHelpIconButton(getHelpBtnContext()); bottom.add(helpBtn, BorderLayout.WEST); add(bottom, BorderLayout.SOUTH); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:org.o3project.optsdn.don.frame.NeFrame.java
/** * Create a pane that displays OMS connection information. * // www. jav a2s . c om * @return The pane that displays OMS connection information */ private JScrollPane createOmsConnectionInfoPane() { Object[] header = OMS_CONNECTION_INFO_COLNAME_LIST.toArray(); String[][] rowDataList = new String[omsConnectionInfoList.size()][header.length]; for (int i = 0; i < rowDataList.length; i++) { List<Port> omsConnectionInfo = omsConnectionInfoList.get(i); Port port = omsConnectionInfo.get(0); int ofPortIndex = OMS_CONNECTION_INFO_COLNAME_LIST.indexOf(OmsConnectionInfoCols.OF_PORT.getName()); Integer openFlowPortId1 = port.getOpenFlowPortId(); String ofPortValue1; if (openFlowPortId1 == null) { ofPortValue1 = OFPORT_NOTFOUND; } else { ofPortValue1 = String.valueOf(openFlowPortId1); } rowDataList[i][ofPortIndex] = ofPortValue1; Port port2 = omsConnectionInfo.get(1); int connectedToIndex = OMS_CONNECTION_INFO_COLNAME_LIST .indexOf(OmsConnectionInfoCols.CONNECTED_TO.getName()); Integer openFlowPortId2 = port2.getOpenFlowPortId(); String ofPortValue2; if (openFlowPortId2 == null) { ofPortValue2 = OFPORT_NOTFOUND; } else { ofPortValue2 = String.valueOf(openFlowPortId2); } rowDataList[i][connectedToIndex] = port2.getNeId() + ", " + ofPortValue2; } JTable connectedTable = new JTable(rowDataList, header); connectedTable.getTableHeader().setBackground(Color.WHITE); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); for (int i = 0; i < header.length; i++) { TableColumn column = connectedTable.getColumnModel().getColumn(i); column.setCellRenderer(renderer); } JScrollPane connectedPane = new JScrollPane(); connectedPane.getViewport().setView(connectedTable); connectedPane.setPreferredSize(new Dimension(connectedPane.getPreferredSize().width, TABLE_HEIGHT)); return connectedPane; }
From source file:org.o3project.optsdn.don.frame.NeFrame.java
/** * Create a pane that displays Information Model ID list. * //from w ww .ja v a2 s. c o m * @param portList Ports * @return The pane that displays Information Model ID list */ private JScrollPane createInformationModelIdListPane(List<Port> portList) { Collections.sort(portList, new PortComparator()); Object[] columnNames = INFORMATION_MODEL_ID_COLNAME_LIST.toArray(); DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0); for (Port port : portList) { Port[] column = { port, port }; tableModel.addRow(column); } JTable informationModeldTable = new JTable(tableModel); informationModeldTable.getTableHeader().setBackground(Color.WHITE); DefaultTableCellRenderer renderer = new InformationModelIdRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); informationModeldTable.setDefaultRenderer(Object.class, renderer); JScrollPane informationModelIdPane = new JScrollPane(); informationModelIdPane.getViewport().setView(informationModeldTable); informationModelIdPane .setPreferredSize(new Dimension(informationModelIdPane.getPreferredSize().width, TABLE_HEIGHT)); return informationModelIdPane; }
From source file:org.openconcerto.erp.core.humanresources.payroll.element.VariablePayeSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private ValidState validVarName; private JRadioButton radioVal = new JRadioButton("Valeur"); private JRadioButton radioFormule = new JRadioButton("Formule"); private final JTextField textValeur = new JTextField(); // private final ITextArea textFormule = new ITextArea(); private final VariableTree treeVariable = new VariableTree(); private final JTextField textNom = new JTextField(); private final JLabel labelWarningBadVar = new JLabelWarning(); private ElementComboBox comboSelSal; private EditFrame edit = null; private final SQLJavaEditor textFormule = new SQLJavaEditor(getMapTree()); public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.validVarName = null; this.textFormule.setEditable(false); // Arbre des variables JScrollPane sc = new JScrollPane(this.treeVariable); sc.setPreferredSize(new Dimension(150, sc.getPreferredSize().height)); this.treeVariable.addMouseListener(new MouseAdapter() { public void mousePressed(final MouseEvent mE) { if (mE.getButton() == MouseEvent.BUTTON3) { JPopupMenu menuDroit = new JPopupMenu(); TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); final Object obj = path.getLastPathComponent(); if ((obj == null) || !(obj instanceof VariableRowTreeNode)) { return; }/*ww w .ja v a2 s . c om*/ menuDroit.add(new AbstractAction("Editer") { public void actionPerformed(ActionEvent e) { if (edit == null) { edit = new EditFrame(getElement(), EditFrame.MODIFICATION); } System.err.println("Action performed"); if (obj != null) { System.err.println("Object not null --> " + obj.toString()); if (obj instanceof VariableRowTreeNode) { System.err.println("Object VariableRowTreeNode"); VariableRowTreeNode varNode = (VariableRowTreeNode) obj; edit.selectionId(varNode.getID(), 1); edit.setVisible(true); } } } }); menuDroit.show((Component) mE.getSource(), mE.getPoint().x, mE.getPoint().y); } else { if (mE.getClickCount() == 2) { TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); Object obj = path.getLastPathComponent(); if (obj != null) { if (obj instanceof FormuleTreeNode) { final FormuleTreeNode n = (FormuleTreeNode) obj; int start = textFormule.getSelectionStart(); String tmp = textFormule.getText(); textFormule.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length())); } } } } } }); JPanel panelDroite = new JPanel(); panelDroite.setLayout(new GridBagLayout()); // Categorie JTextField textCategorie = new JTextField(); c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy = 0; JLabel labelCategorie = new JLabel("Catgorie"); panelDroite.add(labelCategorie, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(textCategorie, c); c.gridwidth = 1; // Nom c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy++; JLabel labelNom = new JLabel("Nom"); panelDroite.add(labelNom, c); c.gridx++; c.weightx = 1; panelDroite.add(this.textNom, c); this.textNom.getDocument().addDocumentListener(new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { updateValidVarName(); } }); c.gridx++; c.weightx = 0; panelDroite.add(this.labelWarningBadVar, c); // Description JLabel labelInfos = new JLabel(getLabelFor("INFOS")); ITextArea textInfos = new ITextArea(); c.gridy++; c.gridx = 1; c.gridwidth = 1; c.weightx = 0; panelDroite.add(labelInfos, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.weighty = 0; panelDroite.add(textInfos, c); // Valeur c.gridx = 1; c.gridy++; c.gridwidth = 1; c.weightx = 0; panelDroite.add(this.radioVal, c); c.gridx++; c.weightx = 1; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textValeur, c); c.gridwidth = 1; c.gridx = 1; c.gridy++; panelDroite.add(this.radioFormule, c); c.gridx++; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textFormule, c); c.gridwidth = 1; ButtonGroup group = new ButtonGroup(); group.add(this.radioVal); group.add(this.radioFormule); this.radioVal.setSelected(true); setFormuleEnabled(false); this.radioVal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(false); } }); this.radioFormule.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(true); } }); c.gridy++; c.gridx = 1; c.weighty = 0; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.comboSelSal = new ElementComboBox(false); this.comboSelSal.init(getDirectory().getElement(SalarieSQLElement.class)); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; panelDroite.add(this.comboSelSal, c); c.gridwidth = 1; JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sc, panelDroite); c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; this.add(split, c); this.addRequiredSQLObject(this.textNom, "NOM"); this.addSQLObject(this.textValeur, "VALEUR"); this.addSQLObject(this.textFormule, "FORMULE"); this.addSQLObject(textCategorie, "CATEGORIE"); this.addSQLObject(textInfos, "INFOS"); this.comboSelSal.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // TODO Auto-generated method stub textFormule.setSalarieID(comboSelSal.getSelectedId()); } }); } @Override public synchronized ValidState getValidState() { return super.getValidState().and(this.validVarName); } private void setFormuleEnabled(boolean b) { if (b) { this.textValeur.setText(""); } else { this.textFormule.setText(""); } this.textValeur.setEditable(!b); this.textValeur.setEnabled(!b); this.textFormule.setEditable(b); this.textFormule.setEnabled(b); this.treeVariable.setEnabled(b); this.treeVariable.setEditable(b); } private void setValidVarName(ValidState s) { if (!s.equals(this.validVarName)) { this.validVarName = s; final boolean warningVisible = !s.isValid(); if (warningVisible) this.labelWarningBadVar.setText(s.getValidationText()); this.labelWarningBadVar.setVisible(warningVisible); this.fireValidChange(); } } private void updateValidVarName() { this.setValidVarName(this.computeValidVarName()); } private ValidState computeValidVarName() { // on vrifie si la syntaxe de la variable est correct (chiffre lettre et _) final String varName = this.textNom.getText().trim(); System.err.println("Verification de la validit du nom de la variable."); if (varName.length() == 0) { return VAR_NO_NAME; } // ne contient que des chiffre lettre et _ et ne commence pas par un chiffre if (!isJavaVar(varName)) { return VAR_NAME_NOT_CORRECT; } // on vrifie que la variable n'existe pas dja SQLSelect selAllVarName = new SQLSelect(getTable().getBase()); selAllVarName.addSelect(VariablePayeSQLElement.this.getTable().getField("ID")); Where w = new Where(VariablePayeSQLElement.this.getTable().getField("NOM"), "=", varName); w = w.and(new Where(VariablePayeSQLElement.this.getTable().getKey(), "!=", getSelectedID())); selAllVarName.setWhere(w); String reqAllVarName = selAllVarName.asString();// + " AND '" + varName.trim() + "' // REGEXP VARIABLE_PAYE.NOM"; Object[] objKeysRowName = ((List) getTable().getBase().getDataSource().execute(reqAllVarName, new ArrayListHandler())).toArray(); if (objKeysRowName.length > 0) { return VAR_ALREADY_EXIST; } else { // Impossible de crer une variable du meme nom qu'un champ du salarie if (isForbidden(varName)) return VAR_ALREADY_EXIST; this.textFormule.setVarAssign(varName); return ValidState.getTrueInstance(); } } private boolean isJavaVar(String s) { if ((s.charAt(0) >= '0') && ((s.charAt(0) <= '9'))) { System.err.println("Erreur la variable commence par un chiffre!!"); return false; } else { for (int i = 0; i < s.length(); i++) { if (!(((s.charAt(i) >= '0') && (s.charAt(i) <= '9')) || (s.charAt(i) >= 'a') && (s.charAt(i) <= 'z') || (s.charAt(i) >= 'A') && (s.charAt(i) <= 'Z') || (s.charAt(i) == '_'))) { System.err.println("Erreur la variable contient un caractere incorrect!!"); return false; } } return (!CTokenMarker.getKeywords().isExisting(s)); } } @Override public void select(SQLRowAccessor r) { super.select(r); // System.err.println("Select RowAccess -------> " + r.getID() + " For Object " + // this.hashCode()); if (r != null) { if (r.getString("FORMULE").trim().length() == 0) { this.radioVal.setSelected(true); setFormuleEnabled(false); } else { this.radioFormule.setSelected(true); setFormuleEnabled(true); } this.textFormule.setVarAssign(r.getString("NOM")); } this.updateValidVarName(); } }; }
From source file:org.revager.gui.findings_list.FindingsListFrame.java
private void createCommAndRatePanel() { JLabel recLbl = new JLabel(translate("Final recommendation for the product:")); recLbl.setFont(UI.VERY_LARGE_FONT_BOLD); JLabel meetCommLbl = new JLabel(translate("Comments on the meeting:")); meetCommLbl.setFont(UI.VERY_LARGE_FONT_BOLD); JLabel protCommLbl = new JLabel(translate("Comments on the list of findings:")); protCommLbl.setFont(UI.VERY_LARGE_FONT_BOLD); meetCommTxtArea = new JTextArea(); meetCommTxtArea.setRows(4);//from ww w. j a v a 2s .c o m meetCommTxtArea.setFont(UI.VERY_LARGE_FONT); protCommTxtArea = new JTextArea(); protCommTxtArea.setRows(4); protCommTxtArea.setFont(UI.VERY_LARGE_FONT); recBx = new JComboBox<>(); recBx.setEditable(true); recBx.setFont(UI.VERY_LARGE_FONT); /* * adding focus and tab listeners to TextAreas */ meetCommTxtArea.addKeyListener(updateListener); meetCommTxtArea.addKeyListener(tabKeyListener); protCommTxtArea.addKeyListener(updateListener); protCommTxtArea.addKeyListener(tabKeyListener); for (String rec : Data.getDefaultRecommendations()) { recBx.addItem(rec); } recBx.setSelectedIndex(0); recBx.addItemListener(itemListener); recBx.setSelectedItem(revMgmt.getRecommendation().trim()); meetCommTxtArea.setText(Application.getInstance().getMeetingMgmt().getMeetingComment(currentMeet).trim()); protCommTxtArea.setText(protMgmt.getProtocolComment(currentProt).trim()); JScrollPane meetCommScrllPn = GUITools.setIntoScrllPn(meetCommTxtArea); meetCommScrllPn.setMinimumSize(meetCommScrllPn.getPreferredSize()); GUITools.scrollToTop(meetCommScrllPn); protCommScrllPn = GUITools.setIntoScrllPn(protCommTxtArea); protCommScrllPn.setMinimumSize(protCommScrllPn.getPreferredSize()); GUITools.scrollToTop(protCommScrllPn); GUITools.addComponent(tabPanelCommAndRec, gbl, recLbl, 0, 3, 2, 1, 0.0, 0.0, 20, 10, 0, 10, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, recBx, 0, 4, 2, 1, 1.0, 0.0, 5, 10, 0, 10, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, meetCommLbl, 0, 5, 1, 1, 1.0, 0.0, 25, 10, 0, 10, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, meetCommScrllPn, 0, 6, 1, 1, 1.0, 1.0, 5, 10, 0, 10, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, protCommLbl, 1, 5, 1, 1, 1.0, 0.0, 25, 10, 0, 10, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); GUITools.addComponent(tabPanelCommAndRec, gbl, protCommScrllPn, 1, 6, 1, 1, 1.0, 1.0, 5, 10, 0, 10, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST); tabPanelCommAndRec.setBorder(new EmptyBorder(0, 10, 20, 10)); }
From source file:org.yccheok.jstock.gui.Utils.java
/** * Adjust popup for combo box, so that horizontal scrollbar will not display. * http://forums.oracle.com/forums/thread.jspa?messageID=8037483� * http://www.camick.com/java/source/BoundsPopupMenuListener.java * * Update : According to https://forums.oracle.com/forums/thread.jspa?messageID=9789603#9789603 * , the above techniques is longer workable. * ========================================================================= * 6u25 changed when popupMenuWillBecomeVisible is called: it is now called * before the list is created so you can add items in that method and still * have the list size correctly./* w w w. j a va2 s .c om*/ * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4743225 * So for your workaround: either it isn't needed anymore or you need to add * an extra hierarchy listener to check when the list is actually added. * ========================================================================= * * I use a quick hack from * http://javabyexample.wisdomplug.com/java-concepts/34-core-java/59-tips-and-tricks-for-jtree-jlist-and-jcombobox-part-i.html * * @param comboBox The combo box */ public static void adjustPopupWidth(JComboBox comboBox) { if (comboBox.getItemCount() == 0) return; Object comp = comboBox.getAccessibleContext().getAccessibleChild(0); if (!(comp instanceof BasicComboPopup)) { return; } BasicComboPopup popup = (BasicComboPopup) comp; JList list = popup.getList(); JScrollPane scrollPane = getScrollPane(popup); // Just to be paranoid enough. if (list == null || scrollPane == null) { return; } // Determine the maximimum width to use: // a) determine the popup preferred width // b) ensure width is not less than the scroll pane width int popupWidth = list.getPreferredSize().width + 5 // make sure horizontal scrollbar doesn't appear + getScrollBarWidth(comboBox, scrollPane); Dimension scrollPaneSize = scrollPane.getPreferredSize(); //popupWidth = Math.max(popupWidth, scrollPaneSize.width); // Use comboBox.getSize(), since we realize under Linux's Java 6u25, // After expanding, scrollPane.getPreferredSize() will return expanded // size in the 2nd round, although no expand is required. popupWidth = Math.max(popupWidth, comboBox.getSize().width); // Adjust the width scrollPaneSize.width = popupWidth; scrollPane.setPreferredSize(scrollPaneSize); scrollPane.setMaximumSize(scrollPaneSize); // The above workaround is no longer working. Use the below hack code! if (comboBox instanceof JComboBoxPopupAdjustable) { ((JComboBoxPopupAdjustable) comboBox).setPopupWidth(popupWidth); } }