Example usage for javax.swing JScrollPane setPreferredSize

List of usage examples for javax.swing JScrollPane setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JScrollPane setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:com.ficeto.esp.EspExceptionDecoder.java

private void createAndUpload() {
    if (!PreferencesData.get("target_platform").contentEquals("esp8266")
            && !PreferencesData.get("target_platform").contentEquals("esp32")
            && !PreferencesData.get("target_platform").contentEquals("ESP31B")) {
        System.err.println();/*  w  w w .j ava 2 s .  c o m*/
        editor.statusError("Not Supported on " + PreferencesData.get("target_platform"));
        return;
    }

    String tc = "esp32";
    if (PreferencesData.get("target_platform").contentEquals("esp8266")) {
        tc = "lx106";
    }

    TargetPlatform platform = BaseNoGui.getTargetPlatform();

    String gccPath = PreferencesData.get("runtime.tools.xtensa-" + tc + "-elf-gcc.path");
    if (gccPath == null) {
        gccPath = platform.getFolder() + "/tools/xtensa-" + tc + "-elf";
    }

    String addr2line;
    if (PreferencesData.get("runtime.os").contentEquals("windows"))
        addr2line = "xtensa-" + tc + "-elf-addr2line.exe";
    else
        addr2line = "xtensa-" + tc + "-elf-addr2line";

    tool = new File(gccPath + "/bin", addr2line);
    if (!tool.exists() || !tool.isFile()) {
        System.err.println();
        editor.statusError("ERROR: " + addr2line + " not found!");
        return;
    }

    elf = new File(getBuildFolderPath(editor.getSketch()), editor.getSketch().getName() + ".ino.elf");
    if (!elf.exists() || !elf.isFile()) {
        elf = new File(getBuildFolderPath(editor.getSketch()), editor.getSketch().getName() + ".cpp.elf");
        if (!elf.exists() || !elf.isFile()) {
            //lets give the user a chance to select the elf
            final JFileChooser fc = new JFileChooser();
            fc.addChoosableFileFilter(new ElfFilter());
            fc.setAcceptAllFileFilterUsed(false);
            int returnVal = fc.showDialog(editor, "Select ELF");
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                elf = fc.getSelectedFile();
            } else {
                editor.statusError("ERROR: elf was not found!");
                System.err.println("Open command cancelled by user.");
                return;
            }
        }
    }

    JFrame.setDefaultLookAndFeelDecorated(true);
    frame = new JFrame("Exception Decoder");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    inputArea = new JTextArea("Paste your stack trace here", 16, 60);
    inputArea.setLineWrap(true);
    inputArea.setWrapStyleWord(true);
    inputArea.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "commit");
    inputArea.getActionMap().put("commit", new CommitAction());
    inputArea.getDocument().addDocumentListener(this);
    frame.getContentPane().add(new JScrollPane(inputArea), BorderLayout.PAGE_START);

    outputText = "";
    outputArea = new JTextPane();
    outputArea.setContentType("text/html");
    outputArea.setEditable(false);
    outputArea.setBackground(null);
    outputArea.setBorder(null);
    outputArea.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    outputArea.setText(outputText);

    JScrollPane outputScrollPane = new JScrollPane(outputArea);
    outputScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    outputScrollPane.setPreferredSize(new Dimension(640, 200));
    outputScrollPane.setMinimumSize(new Dimension(10, 10));
    frame.getContentPane().add(outputScrollPane, BorderLayout.CENTER);

    frame.pack();
    frame.setVisible(true);
}

From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java

/**
 * Constructor//  ww w.j a  va2 s . c  om
 * 
 * @param compactLayout
 *            if false, there will be message type selectors in the panel
 */
public ChatServicePanel(boolean compactLayout) {
    super(new BorderLayout());

    // Prepare the title header
    titleHeader.setBackground(getBackground().darker());
    titleHeader.setOpaque(true);
    titleHeader.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    titleHeader.setHorizontalAlignment(SwingConstants.CENTER);
    add(titleHeader, BorderLayout.NORTH);

    // Add messages panel
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    messagesPanel.setBackground(UIManager.getColor("List.background"));
    messagesPanel.setOpaque(false);
    messagesPanel.setLayout(new GridBagLayout());
    messagesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(scrollPane, BorderLayout.CENTER);

    JPanel sendPanel = new JPanel(new GridBagLayout());
    add(sendPanel, BorderLayout.SOUTH);
    Insets insets = new Insets(2, 2, 2, 2);

    // Add text area
    if (compactLayout) {
        messageText = new JTextField();
        ((JTextField) messageText).addActionListener(this);
        sendPanel.add(messageText, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, NORTH, BOTH, insets, 0, 0));

    } else {
        messageText = new JTextArea();
        JScrollPane scrollPane2 = new JScrollPane(messageText);
        scrollPane2.setPreferredSize(new Dimension(100, 50));
        scrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        sendPanel.add(scrollPane2, new GridBagConstraints(0, 0, 1, 2, 1.0, 1.0, NORTH, BOTH, insets, 0, 0));
    }

    // Add buttons
    ButtonGroup group = new ButtonGroup();
    messageTypeBtn = createMessageTypeButton("Send messages", ICON_MESSAGE, true, group);
    warningTypeBtn = createMessageTypeButton("Send warnings", ICON_WARNING, false, group);
    alertTypeBtn = createMessageTypeButton("Send alerts", ICON_ALERT, false, group);

    if (!compactLayout) {
        JToolBar msgTypePanel = new JToolBar();
        msgTypePanel.setBorderPainted(false);
        msgTypePanel.setOpaque(true);
        msgTypePanel.setFloatable(false);
        sendPanel.add(msgTypePanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0));
        msgTypePanel.add(messageTypeBtn);
        msgTypePanel.add(warningTypeBtn);
        msgTypePanel.add(alertTypeBtn);
    }

    if (compactLayout) {
        sendBtn = new JButton("Send");
        sendPanel.add(sendBtn, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0));
    } else {
        sendBtn = new JButton("Send", ICON_MESSAGE);
        sendBtn.setPreferredSize(new Dimension(100, sendBtn.getPreferredSize().height));
        sendPanel.add(sendBtn, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0));
    }
    sendBtn.setEnabled(false);
    messageText.setEditable(false);
    sendBtn.addActionListener(this);
}

From source file:statistic.graph.Controller.java

public void notify(DiagramEvent event) {
    LOGGER.entering("Controller", "notify", event);
    DiagramData data = event.getDiagram();
    if (data == null) {
        return;/* w ww .  j a v  a  2  s .c o m*/
    }
    if (event instanceof DiagramChangedEvent) {
        ChartPanel chartPanel = chartPanels.get(data);
        if (chartPanel != null) {
            if (event instanceof DiagramTitleChangedEvent) {
                chartPanel.getChart().setTitle(((DiagramTitleChangedEvent) event).getNewTitle());
            } else if (event instanceof DiagramXAxisLabelChangedEvent) {
                chartPanel.getChart().getXYPlot().getDomainAxis()
                        .setLabel(((DiagramXAxisLabelChangedEvent) event).getNewXAxisLabel());
            } else if (event instanceof DiagramYAxisLabelChangedEvent) {
                chartPanel.getChart().getXYPlot().getRangeAxis()
                        .setLabel(((DiagramYAxisLabelChangedEvent) event).getNewYAxisLabel());
            } else {
                throw new AssertionError("This should not happen.");
            }
            chartPanel.chartChanged(
                    new ChartChangeEvent(event, chartPanel.getChart(), ChartChangeEventType.GENERAL));
        }
    } else if (event instanceof DiagramSelectionChangedEvent) {
    } else {
        if (event instanceof DiagramAddedEvent) {
            if (data.getType() == DiagramType.TABLE) {
                JTable table = createTable(data);
                JScrollPane pane = new JScrollPane(table);
                pane.setPreferredSize(new Dimension(scrollPane.getWidth() / 2 - 14, 300));
                tableScrollPanes.put(data, pane);
                contentPane.add(pane);
            } else {
                ChartPanel chartPanel = createChartPanel(data);
                //chartPanel.setPreferredSize(new Dimension(scrollPane.getWidth() / 2 - 14, 300));
                chartPanels.put(data, chartPanel);
                contentPane.add(chartPanel);
            }
        } else if (event instanceof DiagramRemovedEvent) {
            if (data.getType() == DiagramType.TABLE) {
                JScrollPane pane = tableScrollPanes.remove(data);
                contentPane.remove(pane);
            } else {
                ChartPanel chartPanel = chartPanels.remove(data);
                contentPane.remove(chartPanel);
            }
        } else if (event instanceof DiagramSequenceChangedEvent) {
            DiagramData data2 = ((DiagramSequenceChangedEvent) event).getDiagram2();
            Component component1 = getComponent(data);
            LOGGER.finest("1. Komponente: " + component1);
            Component component2 = getComponent(data2);
            LOGGER.finest("2. Komponente: " + component2);
            int index = 0;
            for (Component component : contentPane.getComponents()) {
                if (component == component1) {
                    break;
                }
                index++;
            }
            LOGGER.finest("1. Komponente befindet sich an Index: " + index);
            LOGGER.finest("Entferne 2. Komponente");
            contentPane.remove(component2);
            LOGGER.finest("Fge 2. Komponent an Index " + index + " wieder ein.");
            contentPane.add(component2, index);
        } else if (event instanceof DiagramTypeChangedEvent) {
            Component component = null;
            if (chartPanels.containsKey(data)) {
                component = chartPanels.get(data);
            } else if (tableScrollPanes.containsKey(data)) {
                component = tableScrollPanes.get(data);
            }
            int index = 0;
            for (Component c : contentPane.getComponents()) {
                if (c == component) {
                    break;
                }
                index++;
            }
            contentPane.remove(component);
            if (component instanceof ChartPanel) {
                chartPanels.remove(data);
            } else if (component instanceof JScrollPane) {
                tableScrollPanes.remove(data);
            }
            if (data.getType() == DiagramType.TABLE) {
                JTable table = createTable(data);
                JScrollPane pane = new JScrollPane(table);
                pane.setPreferredSize(new Dimension(scrollPane.getWidth() / 2 - 14, 300));
                component = pane;
                tableScrollPanes.put(data, pane);
            } else {
                ChartPanel panel = createChartPanel(data);
                component = panel;
                chartPanels.put(data, panel);
            }
            contentPane.add(component, index);
        } else {
            throw new AssertionError("This should not happen.");
        }
        scrollPane.validate();
        scrollPane.repaint();
    }
}

From source file:marytts.tools.voiceimport.DatabaseImportMain.java

protected void setupGUI() {
    // A scroll pane containing one labelled checkbox per component,
    // and a "run selected components" button below.
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints gridC = new GridBagConstraints();
    getContentPane().setLayout(gridBagLayout);

    JPanel checkboxPane = new JPanel();
    checkboxPane.setLayout(new BoxLayout(checkboxPane, BoxLayout.Y_AXIS));
    //checkboxPane.setPreferredSize(new Dimension(300, 300));
    int compIndex = 0;
    for (int j = 0; j < groups2Comps.length; j++) {
        String[] nextGroup = groups2Comps[j];
        JPanel groupPane = new JPanel();
        groupPane.setLayout(new BoxLayout(groupPane, BoxLayout.Y_AXIS));
        groupPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(nextGroup[0]),
                BorderFactory.createEmptyBorder(1, 1, 1, 1)));
        for (int i = 1; i < nextGroup.length; i++) {
            JButton configButton = new JButton();
            Icon configIcon = new ImageIcon(DatabaseImportMain.class.getResource("configure.png"), "Configure");
            configButton.setIcon(configIcon);
            configButton.setPreferredSize(new Dimension(configIcon.getIconWidth(), configIcon.getIconHeight()));
            configButton.addActionListener(new ConfigButtonActionListener(nextGroup[i]));
            configButton.setBorderPainted(false);
            //System.out.println("Adding checkbox for "+components[i].getClass().getName());
            checkboxes[compIndex] = new JCheckBox(nextGroup[i]);
            checkboxes[compIndex].setFocusable(true);
            //checkboxes[i].setPreferredSize(new Dimension(200, 30));
            JPanel line = new JPanel();
            line.setLayout(new BorderLayout(5, 0));
            line.add(configButton, BorderLayout.WEST);
            line.add(checkboxes[compIndex], BorderLayout.CENTER);
            groupPane.add(line);//from  w w  w .  ja v a2  s . c om
            compIndex++;
        }
        checkboxPane.add(groupPane);
    }
    gridC.gridx = 0;
    gridC.gridy = 0;
    gridC.fill = GridBagConstraints.BOTH;
    JScrollPane scrollPane = new JScrollPane(checkboxPane);
    scrollPane.setPreferredSize(new Dimension(450, 300));
    gridBagLayout.setConstraints(scrollPane, gridC);
    getContentPane().add(scrollPane);

    JButton helpButton = new JButton("Help");
    helpButton.setMnemonic(KeyEvent.VK_H);
    helpButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            displayHelpGUI();
        }
    });
    JButton settingsButton = new JButton("Settings");
    settingsButton.setMnemonic(KeyEvent.VK_S);
    settingsButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            currentComponent = "Global properties";
            displaySettingsGUI();
        }
    });
    runButton = new JButton("Run");
    runButton.setMnemonic(KeyEvent.VK_R);
    runButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            runSelectedComponents();
        }
    });

    JButton quitAndSaveButton = new JButton("Quit");
    quitAndSaveButton.setMnemonic(KeyEvent.VK_Q);
    quitAndSaveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                askIfSave();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            System.exit(0);
        }
    });

    gridC.gridy = 1;
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout());
    //buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS));
    //runButton.setAlignmentX(JButton.LEFT_ALIGNMENT);
    buttonPanel.add(runButton);
    //helpButton.setAlignmentX(JButton.LEFT_ALIGNMENT);
    buttonPanel.add(helpButton);
    //settingsButton.setAlignmentX(JButton.LEFT_ALIGNMENT);
    buttonPanel.add(settingsButton);
    //buttonPanel.add(Box.createHorizontalGlue());
    //quitAndSaveButton.setAlignmentX(JButton.RIGHT_ALIGNMENT);
    buttonPanel.add(quitAndSaveButton);
    gridBagLayout.setConstraints(buttonPanel, gridC);
    getContentPane().add(buttonPanel);

    //getContentPane().setPreferredSize(new Dimension(300, 300));
    // End program when closing window:
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            try {
                askIfSave();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            System.exit(0);
        }
    });
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java

protected void buildUI() {
    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "10px,f:130px:g,10px,p,15px"), this);

    formatSwitchTbl = new JTable(new DefaultTableModel());
    formatSwitchTbl.getSelectionModel().addListSelectionListener(new RowListener());
    addTableModelListener((DefaultTableModel) formatSwitchTbl.getModel());
    fillWithObjFormatter(null);/*  www  .  ja v a  2  s  .c o m*/

    // tool bar to host the add and delete buttons
    createToolbar();

    // lay out components on main panel
    JScrollPane sp = UIHelper.createScrollPane(formatSwitchTbl);
    // set minimum and preferred sizes so that table shrinks with the dialog
    sp.setMinimumSize(new Dimension(50, 5));
    sp.setPreferredSize(new Dimension(50, 5));

    pb.add(sp, cc.xy(1, 2));
    pb.add(controlPanel, cc.xy(1, 4));
    this.mainPanelBuilder = pb;
}

From source file:edu.ucla.stat.SOCR.chart.demo.PowerTransformXYScatterChart.java

protected void setTable(XYDataset ds) {

    convertor.Y2Table(raw_x, raw_y, transformed_x, transformed_y, row_count);
    JTable tempDataTable = convertor.getTable();

    resetTableRows(tempDataTable.getRowCount() + 1);
    resetTableColumns(tempDataTable.getColumnCount());

    for (int i = 0; i < tempDataTable.getColumnCount(); i++) {
        columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i));
        //  System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i));
    }/*from   w w w .  ja va2s. co m*/

    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    for (int i = 0; i < tempDataTable.getRowCount(); i++)
        for (int j = 0; j < tempDataTable.getColumnCount(); j++) {
            dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j);
        }

    dataPanel.removeAll();
    JScrollPane dt = new JScrollPane(dataTable);
    dataPanel.add(dt);
    dt.setRowHeaderView(headerTable);
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);
    dataTable.doLayout();
    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }

    dataPanel.validate();

    // don't bring graph to the front
    if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) != ALL) {
        //   tabbedPanelContainer.setSelectedIndex(tabbedPanelContainer.indexOfComponent(graphPanel));
    } else {
        dataPanel2.removeAll();
        dataPanel2.add(new JLabel(" "));
        dataPanel2.add(new JLabel("Data"));
        JScrollPane dt2 = new JScrollPane(dataTable);
        dt2.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y * 3 / 8));
        dt2.setRowHeaderView(headerTable);
        dataPanel2.add(dt2);
        JScrollPane st = new JScrollPane(summaryPanel);
        st.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y / 6));
        dataPanel2.add(st);
        st.validate();

        dataPanel2.add(new JLabel(" "));
        dataPanel2.add(new JLabel("Mapping"));
        mapPanel.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y / 2));
        dataPanel2.add(mapPanel);

        dataPanel2.validate();
    }
}

From source file:eu.lp0.cursus.ui.AboutDialog.java

private void initialise() {
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(Messages.getString("about.title", Constants.APP_DESC)); //$NON-NLS-1$
    DefaultUnitConverter duc = DefaultUnitConverter.getInstance();

    FormLayout layout = new FormLayout("2dlu, pref, fill:pref:grow, max(30dlu;pref), 2dlu", //$NON-NLS-1$
            "2dlu, max(15dlu;pref), 2dlu, max(15dlu;pref), 2dlu, fill:max(100dlu;pref):grow, 2dlu, max(16dlu;pref), 2dlu"); //$NON-NLS-1$
    getContentPane().setLayout(layout);//  w w w  . ja  v a 2s .c om

    JLabel lblName = new JLabel(Constants.APP_NAME + ": " + Messages.getString("about.description")); //$NON-NLS-1$ //$NON-NLS-2$
    getContentPane().add(lblName, "2, 2, 3, 1"); //$NON-NLS-1$

    getContentPane().add(new LinkJButton(Constants.APP_URL), "2, 4"); //$NON-NLS-1$

    JScrollPane scrCopying = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    getContentPane().add(scrCopying, "2, 6, 3, 1"); //$NON-NLS-1$

    JTextArea txtCopying = new JTextArea(loadResources("COPYRIGHT", "LICENCE")); //$NON-NLS-1$ //$NON-NLS-2$
    txtCopying.setFont(Font.decode(Font.MONOSPACED));
    txtCopying.setEditable(false);
    scrCopying.setViewportView(txtCopying);
    scrCopying.setPreferredSize(
            new Dimension(scrCopying.getPreferredSize().width, duc.dialogUnitYAsPixel(100, scrCopying)));

    Action actClose = new CloseDialogAction(this);
    JButton btnClose = new JButton(actClose);
    getContentPane().add(btnClose, "4, 8"); //$NON-NLS-1$

    getRootPane().setDefaultButton(btnClose);
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CloseDialogAction.class.getName());
    getRootPane().getActionMap().put(CloseDialogAction.class.getName(), actClose);

    pack();
    setMinimumSize(getSize());
    setSize(getSize().width, getSize().height * 3 / 2);
    btnClose.requestFocusInWindow();
}

From source file:com.wwidesigner.gui.StudyView.java

@Override
protected void initializeComponents() {
    // create file tree
    tree = new JTree() {
        @Override/*  ww w  .ja  va  2 s.  c  o m*/
        public String getToolTipText(MouseEvent e) {
            String tip = null;
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path != null) {
                if (path.getPathCount() == 3) // it is a leaf
                {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                    if (node instanceof TreeNodeWithToolTips) {
                        tip = ((TreeNodeWithToolTips) node).getToolTip();
                    }
                }
            }
            return tip == null ? getToolTipText() : tip;
        }
    };
    // Show tooltips for the Study view, and let them persist for 8 seconds.
    ToolTipManager.sharedInstance().registerComponent(tree);
    ToolTipManager.sharedInstance().setDismissDelay(8000);
    // If a Study view node doesn't fit in the pane, expand it when hovering
    // over it.
    ExpandedTipUtils.install(tree);
    tree.setRootVisible(false);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path != null) {
                if (path.getPathCount() == 3) // it is a leaf
                {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
                    String category = (String) parentNode.getUserObject();
                    study.setCategorySelection(category, (String) node.getUserObject());
                    if (StudyModel.INSTRUMENT_CATEGORY_ID.equals(category)
                            || StudyModel.TUNING_CATEGORY_ID.equals(category)) {
                        try {
                            study.validHoleCount();
                        } catch (Exception ex) {
                            showException(ex);
                        }
                    }
                }
                updateView();
            }
        }
    });
    JScrollPane scrollPane = new JScrollPane(tree);
    scrollPane.setPreferredSize(new Dimension(225, 100));
    add(scrollPane);

    Preferences myPreferences = getApplication().getPreferences();
    String modelName = myPreferences.get(OptimizationPreferences.STUDY_MODEL_OPT,
            OptimizationPreferences.NAF_STUDY_NAME);
    setStudyModel(modelName);
    study.setPreferences(myPreferences);

    getApplication().getEventManager().subscribe(WIDesigner.FILE_OPENED_EVENT_ID, this);
    getApplication().getEventManager().subscribe(WIDesigner.FILE_CLOSED_EVENT_ID, this);
    getApplication().getEventManager().subscribe(WIDesigner.FILE_SAVED_EVENT_ID, this);
    getApplication().getEventManager().subscribe(WIDesigner.WINDOW_RENAMED_EVENT_ID, this);
}

From source file:ca.phon.app.session.editor.view.segmentation.SegmentationEditorView.java

private void init() {
    segmentWindowField = new JTextField();
    SegmentWindowDocument segDoc = new SegmentWindowDocument();
    segmentWindowField.setDocument(segDoc);
    segmentWindowField.setText(DEFAULT_SEGMENT_WINDOW + "");
    segDoc.addDocumentListener(new SegmentWindowListener());

    segmentLabel = new SegmentLabel();
    segmentLabel.setSegmentWindow(DEFAULT_SEGMENT_WINDOW);
    segmentLabel.setCurrentTime(0L);/* w  w w.ja  va  2s. co m*/
    segmentLabel.lockSegmentStartTime(-1L);

    modeBox = new JComboBox(SegmentationMode.values());
    modeBox.setSelectedItem(SegmentationMode.INSERT_AFTER_CURRENT);

    JPanel topPanel = new JPanel();
    FormLayout topLayout = new FormLayout("right:pref, 3dlu, fill:default:grow, pref",
            "pref, pref, pref, pref");
    topPanel.setLayout(topLayout);
    CellConstraints cc = new CellConstraints();
    topPanel.add(new JLabel("Segment Window"), cc.xy(1, 1));
    topPanel.add(segmentWindowField, cc.xy(3, 1));
    topPanel.add(new JLabel("ms"), cc.xy(4, 1));

    JLabel infoLabel = new JLabel("Set to 0 for unlimited segment time");
    infoLabel.setFont(infoLabel.getFont().deriveFont(10.0f));

    topPanel.add(infoLabel, cc.xy(3, 2));
    topPanel.add(new JLabel("Current Window"), cc.xy(1, 3));
    topPanel.add(segmentLabel, cc.xy(3, 3));

    topPanel.add(new JLabel("Mode"), cc.xy(1, 4));
    topPanel.add(modeBox, cc.xyw(3, 4, 2));

    setLayout(new BorderLayout());
    add(topPanel, BorderLayout.NORTH);

    participantPanel = new JPanel();

    participantPanel.setBackground(Color.white);
    participantPanel.setOpaque(true);

    JScrollPane participantScroller = new JScrollPane(participantPanel);
    Dimension prefSize = participantScroller.getPreferredSize();
    prefSize.height = 150;
    participantScroller.setPreferredSize(prefSize);
    Dimension maxSize = participantScroller.getMaximumSize();
    maxSize.height = 200;
    participantScroller.setMaximumSize(maxSize);
    Dimension minSize = participantScroller.getMinimumSize();
    minSize.height = 100;
    participantScroller.setMinimumSize(minSize);
    participantScroller.setBorder(BorderFactory.createTitledBorder("Participants"));

    add(participantScroller, BorderLayout.CENTER);

    updateParticipantPanel();
    setupEditorActions();
}

From source file:org.jdal.swing.Selector.java

/**
 * Initialize component after construction.
 *///  w ww. j a va2s  .com
@PostConstruct
public void init() {
    if (availableList == null) {
        availableList = new JList<T>(available);
    } else {
        availableList.setModel(available);
    }
    if (selectedList == null) {
        selectedList = new JList<T>(selected);
    } else {
        selectedList.setModel(selected);
    }

    availableSearch.setVisible(showSearchFields);
    selectedSearch.setVisible(showSearchFields);

    JButton addButton = new JButton(new AddSelectedAction());
    JButton removeButton = new JButton(new RemoveSelectedAction());
    addButton.setMinimumSize(new Dimension(buttonWidth, buttonHeight));
    removeButton.setMinimumSize(new Dimension(buttonWidth, buttonHeight));

    JScrollPane availableScroll = new JScrollPane(availableList);
    JScrollPane selectedScroll = new JScrollPane(selectedList);
    availableScroll.setPreferredSize(new Dimension(listWidth, listheight));
    selectedScroll.setPreferredSize(new Dimension(listWidth, listheight));
    availableScroll.setMinimumSize(new Dimension(listWidth, listheight));
    selectedScroll.setMinimumSize(new Dimension(listWidth, listheight));

    // test message source
    if (messageSource == null) {
        messageSource = new ResourceBundleMessageSource();
        ((ResourceBundleMessageSource) messageSource).setBasename("i18n.jdal");
    }

    MessageSourceAccessor msa = new MessageSourceAccessor(messageSource);

    BoxFormBuilder fb = new BoxFormBuilder();

    fb.row(Short.MAX_VALUE);
    fb.startBox();
    fb.row();
    fb.add(availableSearch);
    fb.row();
    fb.add(FormUtils.newLabelForBox(msa.getMessage("Selector.available")));
    fb.row(Short.MAX_VALUE);
    fb.add(availableScroll);
    fb.endBox();
    fb.startBox();
    fb.row(Short.MAX_VALUE);
    fb.add(Box.createVerticalGlue());
    fb.row(buttonHeight);
    fb.add(removeButton);
    fb.row(Short.MAX_VALUE);
    fb.add(Box.createVerticalGlue());
    fb.endBox();
    fb.setMaxWidth(buttonWidth);
    fb.startBox();
    fb.row(Short.MAX_VALUE);
    fb.add(Box.createVerticalGlue());
    fb.row(buttonHeight);
    fb.add(addButton);
    fb.row(Short.MAX_VALUE);
    fb.add(Box.createVerticalGlue());
    fb.endBox();
    fb.setMaxWidth(buttonWidth);
    fb.startBox();
    fb.row();
    fb.add(selectedSearch);
    fb.row();
    fb.add(FormUtils.newLabelForBox(msa.getMessage("Selector.selected")));
    fb.row(Short.MAX_VALUE);
    fb.add(selectedScroll);
    fb.endBox();

    setLayout(new BorderLayout());
    add(fb.getForm(), BorderLayout.CENTER);
}