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:net.pms.encoders.AviSynthMEncoder.java

@Override
public JComponent config() {
    FormLayout layout = new FormLayout("left:pref, 0:grow",
            "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 12dlu, p, 3dlu, 0:grow");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.EMPTY);//w w  w. j av a 2s  .  c o m
    builder.opaque(false);

    CellConstraints cc = new CellConstraints();

    JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), cc.xyw(2, 1, 1));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    multithreading = new JCheckBox(Messages.getString("MEncoderVideo.35"),
            configuration.getAvisynthMultiThreading());
    multithreading.setContentAreaFilled(false);
    multithreading.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAvisynthMultiThreading((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(multithreading), cc.xy(2, 3));

    interframe = new JCheckBox(Messages.getString("AviSynthMEncoder.13"),
            configuration.getAvisynthInterFrame());
    interframe.setContentAreaFilled(false);
    interframe.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setAvisynthInterFrame(interframe.isSelected());
            if (configuration.getAvisynthInterFrame()) {
                JOptionPane.showMessageDialog(
                        SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()),
                        Messages.getString("AviSynthMEncoder.16"), Messages.getString("Dialog.Information"),
                        JOptionPane.INFORMATION_MESSAGE);
            }
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(interframe), cc.xy(2, 5));

    interframegpu = new JCheckBox(Messages.getString("AviSynthMEncoder.15"),
            configuration.getAvisynthInterFrameGPU());
    interframegpu.setContentAreaFilled(false);
    interframegpu.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAvisynthInterFrameGPU((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(interframegpu), cc.xy(2, 7));

    convertfps = new JCheckBox(Messages.getString("AviSynthMEncoder.3"), configuration.getAvisynthConvertFps());
    convertfps.setContentAreaFilled(false);
    convertfps.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAvisynthConvertFps((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(convertfps), cc.xy(2, 9));

    String aviSynthScriptInstructions = Messages.getString("AviSynthMEncoder.4")
            + Messages.getString("AviSynthMEncoder.5") + Messages.getString("AviSynthMEncoder.6")
            + Messages.getString("AviSynthMEncoder.7") + Messages.getString("AviSynthMEncoder.8");
    JTextArea aviSynthScriptInstructionsContainer = new JTextArea(aviSynthScriptInstructions);
    aviSynthScriptInstructionsContainer.setEditable(false);
    aviSynthScriptInstructionsContainer.setBorder(BorderFactory.createEtchedBorder());
    aviSynthScriptInstructionsContainer.setBackground(new Color(255, 255, 192));
    aviSynthScriptInstructionsContainer.setBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(new Color(130, 135, 144)),
                    BorderFactory.createEmptyBorder(3, 5, 3, 5)));
    builder.add(aviSynthScriptInstructionsContainer, cc.xy(2, 11));

    String clip = configuration.getAvisynthScript();
    if (clip == null) {
        clip = "";
    }
    StringBuilder sb = new StringBuilder();
    StringTokenizer st = new StringTokenizer(clip, PMS.AVS_SEPARATOR);
    int i = 0;
    while (st.hasMoreTokens()) {
        if (i > 0) {
            sb.append("\n");
        }
        sb.append(st.nextToken());
        i++;
    }
    textArea = new JTextArea(sb.toString());
    textArea.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            StringBuilder sb = new StringBuilder();
            StringTokenizer st = new StringTokenizer(textArea.getText(), "\n");
            int i = 0;
            while (st.hasMoreTokens()) {
                if (i > 0) {
                    sb.append(PMS.AVS_SEPARATOR);
                }
                sb.append(st.nextToken());
                i++;
            }
            configuration.setAvisynthScript(sb.toString());
        }
    });

    JScrollPane pane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setPreferredSize(new Dimension(500, 350));
    builder.add(pane, cc.xy(2, 13));

    configuration.addConfigurationListener(new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if (event.getPropertyName() == null) {
                return;
            }
            if ((!event.isBeforeUpdate())
                    && event.getPropertyName().equals(PmsConfiguration.KEY_GPU_ACCELERATION)) {
                interframegpu.setEnabled(configuration.isGPUAcceleration());
            }
        }
    });

    return builder.getPanel();
}

From source file:ca.sqlpower.swingui.enterprise.client.ServerProjectsManagerPanel.java

/**
 * This constructor creates a dialog for modifying and loading a project
 * from a single server designated by the given serverInfo parameter.
 * /*w  w w . j a v  a 2s.  c o m*/
 * @param serverInfo
 *            Projects will be retrieved from this server based on the
 *            information and displayed. The dialog will allow editing the
 *            security as well as creating and deleting projects on this
 *            server.
 * @param dialogOwner
 *            The dialog to parent new dialogs to.
 * @param upf
 *            A user prompter factory for displaying error and warning
 *            messages to users.
 * @param closeAction
 *            An action that will close the dialog or frame that this dialog
 *            is contained in.
 * @param defaultFileDirectory
 *            A default file directory to start looking for files in if the
 *            user wants to upload a project. If null this will default to
 *            the user's home directory.
 * @param cookieStore
 *            A cookie store for HTTP requests. Used by the
 *            {@link ClientSideSessionUtils}.
 */
public ServerProjectsManagerPanel(SPServerInfo serverInfo, Component dialogOwner, UserPrompterFactory upf,
        Action closeAction, File defaultFileDirectory, CookieStore cookieStore) {
    this.serverInfo = serverInfo;
    this.dialogOwner = dialogOwner;
    this.upf = upf;
    this.closeAction = closeAction;
    this.defaultFileDirectory = defaultFileDirectory;
    this.cookieStore = cookieStore;

    cookieStore.clear();

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("pref:grow, 5dlu, pref", "pref, pref, pref"));

    servers = null;

    projects = new JList(new DefaultListModel());
    projects.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            refreshPanel();
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                getOpenAction().actionPerformed(null);
            }
        }
    });

    JScrollPane projectsPane = new JScrollPane(projects);
    projectsPane.setPreferredSize(new Dimension(250, 300));

    CellConstraints cc = new CellConstraints();
    builder.add(new JLabel(serverInfo.getName() + "'s projects:"), cc.xyw(1, 1, 2));
    builder.nextLine();
    builder.add(projectsPane, cc.xywh(1, 2, 1, 2));

    DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
    buttonBarBuilder.append(new JButton(refreshAction));
    buttonBarBuilder.append(securityButton);
    buttonBarBuilder.append(new JButton(newAction));
    buttonBarBuilder.append(openButton);
    buttonBarBuilder.append(new JButton(deleteAction));
    buttonBarBuilder.append(new JButton(closeAction));
    builder.add(buttonBarBuilder.getPanel(), cc.xy(3, 2));
    builder.setDefaultDialogBorder();
    panel = builder.getPanel();
}

From source file:edu.ucla.stat.SOCR.chart.SuperXYZChart.java

protected void setMixPanel() {
    /*super.setMixPanel();
    return;*///from   w w  w . j a v a  2s  .  c  o  m

    dataPanel2.removeAll();
    graphPanel2.removeAll();

    chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X * 2 / 3, CHART_SIZE_Y * 2 / 3));
    graphPanel2.add(chartPanel);
    sliderPanel.removeAll();
    /*   sliderPanel.add(new JLabel("Bin Size"));
         sliderPanel.add(this.binSlider);
         sliderPanel.add(new JLabel(":"+this.binSlider.getValue()));*/
    zSlider.setPreferredSize(new Dimension(CHART_SIZE_X * 2 / 3, 100));
    sliderPanel.add(this.zSlider);
    sliderPanel.setPreferredSize(new Dimension(CHART_SIZE_X * 2 / 3, 100));
    graphPanel2.add(sliderPanel); // the slider
    graphPanel2.validate();

    dataPanel2.add(new JLabel(" "));
    dataPanel2.add(new JLabel("Data"));
    JScrollPane dt = new JScrollPane(dataTable);
    dt.setRowHeaderView(headerTable);
    dt.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y * 3 / 8));

    dataPanel2.add(dt);
    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();

    mixPanel.removeAll();
    mixPanel.add(graphPanel2, BorderLayout.WEST);
    mixPanel.add(new JScrollPane(dataPanel2), BorderLayout.CENTER);
    mixPanel.validate();
}

From source file:ucar.unidata.ui.HttpFormEntry.java

/**
 * Add the label/gui component into the list of components
 *
 * @param guiComps A list.//  w  ww  .j av  a2s . c  om
 */
public void addToGui(List guiComps) {
    if (type == TYPE_HIDDEN) {
        return;
    }
    if (type == TYPE_AREA) {
        guiComps.add(GuiUtils.top(GuiUtils.rLabel(label)));
        if (component == null) {
            component = new JTextArea(value, rows, cols);
            ((JTextArea) component).setLineWrap(true);
        }
        JScrollPane sp = new JScrollPane(component);
        sp.setPreferredSize(new Dimension(500, 200));
        guiComps.add(sp);
    } else if (type == TYPE_INPUT) {
        guiComps.add(GuiUtils.rLabel(label));
        if (component == null) {
            component = new JTextField(value, cols);
        }
        guiComps.add(component);
    } else if (type == TYPE_LABEL) {
        guiComps.add(new JLabel(""));
        guiComps.add(new JLabel(label));
    } else if (type == TYPE_FILE) {
        if (filePartSource == null) {
            guiComps.add(GuiUtils.rLabel(label));
            if (component == null) {
                component = new JTextField(value);
            }
            JButton btn = GuiUtils.makeButton("Browse...", this, "browse", component);
            GuiUtils.setHFill();
            guiComps.add(
                    GuiUtils.doLayout(new Component[] { component, btn }, 2, GuiUtils.WT_YN, GuiUtils.WT_N));
        }
    }
}

From source file:ca.sqlpower.swingui.enterprise.client.ServerProjectsManagerPanel.java

/**
 * Creates a dialog that lets the user choose a server connection and then a
 * project.// w ww.  j av  a  2s  .co m
 * 
 * @param serverManager
 *            This object contains all of the server information objects
 *            known and the servers based on their information will be
 *            displayed in a list so a user can navigate to different
 *            projects in different servers.
 * @param dialogOwner
 *            The dialog to parent new dialogs to.
 * @param upf
 *            A user prompter factory for displaying error and warning
 *            messages to users.
 * @param closeAction
 *            An action that will close the dialog or frame that this dialog
 *            is contained in.
 * @param defaultFileDirectory
 *            A default file directory to start looking for files in if the
 *            user wants to upload a project. If null this will default to
 *            the user's home directory.
 * @param cookieStore
 *            A cookie store for HTTP requests. Used by the
 *            {@link ClientSideSessionUtils}.
 */
public ServerProjectsManagerPanel(SPServerInfoManager serverManager, Component dialogOwner,
        UserPrompterFactory upf, Action closeAction, File defaultFileDirectory, CookieStore cookieStore) {
    this.dialogOwner = dialogOwner;
    this.upf = upf;
    this.closeAction = closeAction;
    this.defaultFileDirectory = defaultFileDirectory;
    this.cookieStore = cookieStore;

    cookieStore.clear();

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("pref:grow, 5dlu, pref:grow, 5dlu, pref", "pref, pref, pref"));

    servers = new JList(new DefaultListModel());
    servers.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e)) {
                refreshInfoList();
            }
        }
    });

    DefaultListModel serversModel = (DefaultListModel) servers.getModel();
    serversModel.removeAllElements();
    if (serverManager.getServers(false).size() > 0) {
        for (SPServerInfo serverInfo : serverManager.getServers(false)) {
            serversModel.addElement(serverInfo);
        }
    } else {
        serversModel.addElement("No Servers");
        servers.setEnabled(false);
    }

    projects = new JList(new DefaultListModel());
    projects.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            refreshPanel();
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                getOpenAction().actionPerformed(null);
            }
        }
    });

    JScrollPane projectsPane = new JScrollPane(projects);
    projectsPane.setPreferredSize(new Dimension(250, 300));

    JScrollPane serverPane = new JScrollPane(servers);
    serverPane.setPreferredSize(new Dimension(250, 300));

    CellConstraints cc = new CellConstraints();
    builder.add(new JLabel("Servers:"), cc.xyw(1, 1, 2));
    builder.add(new JLabel("Projects:"), cc.xyw(3, 1, 2));
    builder.nextLine();
    builder.add(serverPane, cc.xywh(1, 2, 1, 2));
    builder.add(projectsPane, cc.xywh(3, 2, 1, 2));

    DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
    buttonBarBuilder.append(new JButton(refreshAction));
    buttonBarBuilder.append(securityButton);
    buttonBarBuilder.append(new JButton(newAction));
    buttonBarBuilder.append(openButton);
    buttonBarBuilder.append(new JButton(uploadAction));
    buttonBarBuilder.append(new JButton(deleteAction));
    buttonBarBuilder.append(new JButton(closeAction));
    builder.add(buttonBarBuilder.getPanel(), cc.xy(5, 2));
    builder.setDefaultDialogBorder();
    panel = builder.getPanel();
}

From source file:edu.ucla.stat.SOCR.chart.SuperPowerChart.java

/**
* make the show_all panel/*from w  w  w  .  jav a2  s  .  co  m*/
*/
protected void setMixPanel() {
    /*super.setMixPanel();
    return;*/

    dataPanel2.removeAll();
    graphPanel2.removeAll();

    chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X * 2 / 3, CHART_SIZE_Y * 2 / 3));
    graphPanel2.add(chartPanel);
    //   sliderPanel.removeAll();
    /*   sliderPanel.add(new JLabel("Bin Size"));
         sliderPanel.add(this.binSlider);
         sliderPanel.add(new JLabel(":"+this.binSlider.getValue()));*/
    /*   powerSlider.setPreferredSize(new Dimension(CHART_SIZE_X*2/3,100));
         sliderPanel.add(this.powerSlider);
        sliderPanel.setPreferredSize(new Dimension(CHART_SIZE_X*2/3,100));*/
    //   graphPanel2.add(sliderPanel); // the slider
    graphPanel2.validate();

    dataPanel2.add(new JLabel(" "));
    dataPanel2.add(new JLabel("Data"));
    JScrollPane dt = new JScrollPane(dataTable);
    dt.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y * 3 / 8));

    dataPanel2.add(dt);
    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();

    mixPanel.removeAll();
    mixPanel.add(graphPanel2, BorderLayout.WEST);
    mixPanel.add(new JScrollPane(dataPanel2), BorderLayout.CENTER);
    mixPanel.validate();
}

From source file:gui.QTLResultsPanel.java

/** QTLResultsPanel().
 * //  ww  w .  java 2s. co m
 * @param qtlResult = the QTL results to show.
 * @param order = the ordered result data this QTL was created from. 
 */
public QTLResultsPanel(QTLResult qtlResult, OrderedResult order) {
    this.qtlResult = qtlResult;
    this.order = order;

    // Trait listbox
    traitModel = new DefaultListModel<Trait>();
    for (Trait trait : qtlResult.getTraits()) {
        traitModel.addElement(trait);
    }
    traitList = new JList<Trait>(traitModel);
    traitList.addListSelectionListener(this);
    traitList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane sp1 = new JScrollPane(traitList);
    sp1.setPreferredSize(new Dimension(125, 50));

    // Details text box
    details = new JTextArea();
    details.setFont(new Font("Monospaced", Font.PLAIN, 11));
    details.setMargin(new Insets(2, 5, 2, 5));
    details.setEditable(false);
    details.setTabSize(6);
    JScrollPane sp4;
    if (AppFrame.tpmmode == AppFrame.TPMMODE_QTL) {
        simpleDetails = new JScrollPane();
        simpleDetails.setFont(new Font("Monospaced", Font.PLAIN, 11));
        simplesplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        simpleright = new JTextArea();
        simpleright.setFont(new Font("Monospaced", Font.PLAIN, 11));
        simpleright.setMargin(new Insets(2, 5, 2, 5));
        simpleright.setEditable(false);
        simpleright.setTabSize(6);
        simplesplit.setRightComponent(new JScrollPane(simpleright));

        simplesplit.setLeftComponent(simpleDetails);
        sp4 = new JScrollPane(simplesplit);
    } else {
        // TPM MODE NONSNP
        simpleright = new JTextArea();
        simpleright.setFont(new Font("Monospaced", Font.PLAIN, 11));
        simpleright.setMargin(new Insets(2, 5, 2, 5));
        simpleright.setEditable(false);
        sp4 = new JScrollPane(simpleright);
    }

    lodDetails = new JTextArea();
    lodDetails.setFont(new Font("Monospaced", Font.PLAIN, 11));
    lodDetails.setMargin(new Insets(2, 5, 2, 5));
    lodDetails.setEditable(false);
    lodDetails.setTabSize(6);
    JScrollPane sp3 = new JScrollPane(lodDetails);
    JTabbedPane tabs = new JTabbedPane();
    JScrollPane sp2 = new JScrollPane(details);
    tabs.add(sp2, "Full Model");
    tabs.add(sp4, "Simple Model");
    tabs.add(sp3, "LOD Details");

    // The splitpane
    splits = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splits.setTopComponent(new JPanel());
    splits.setBottomComponent(tabs);
    splits.setResizeWeight(0.5);

    // pane2
    JSplitPane splits2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splits2.setLeftComponent(sp1);
    splits2.setRightComponent(splits);

    setLayout(new BorderLayout());
    add(new GradientPanel("QTL Analysis Results"), BorderLayout.NORTH);
    // add(sp1, BorderLayout.WEST);
    // add(splits);
    add(splits2);
    add(toolbar = new QTLResultsToolBar(this), BorderLayout.EAST);
}

From source file:coreferenceresolver.gui.MarkupGUI.java

private JScrollPane newReviewPanel(Review review, int reviewId) throws BadLocationException {
    //Model/*w  ww . j a v a  2  s  . com*/
    ReviewElement reviewElement = new ReviewElement();

    ScrollablePanel reviewPanel = new ScrollablePanel();
    reviewPanel.setLayout(new BoxLayout(reviewPanel, BoxLayout.PAGE_AXIS));

    JTextField title = new JTextField("NEW REVIEW " + reviewId);
    title.setBackground(Color.pink);

    reviewPanel.add(title);

    JTextArea reviewContentTxtArea = new JTextArea();
    reviewContentTxtArea.setLineWrap(true);
    reviewContentTxtArea.setWrapStyleWord(true);
    reviewContentTxtArea.setEditable(false);
    reviewContentTxtArea.setText(review.getRawContent());

    int chainId = 0;
    for (CorefChain cc : review.getCorefChains()) {
        for (int npId : cc.getChain()) {
            NounPhrase np = review.getNounPhrases().get(npId);
            Object highlighTag = reviewContentTxtArea.getHighlighter().addHighlight(np.getOffsetBegin(),
                    np.getOffsetEnd() + 1, highlightPainters.get(chainId));
            this.markupReviews.get(reviewId).getNounPhrases().get(npId).highlighterTag = highlighTag;
        }
        ++chainId;
    }

    reviewPanel.add(reviewContentTxtArea);

    ScrollablePanel markupsPanel = new ScrollablePanel();
    markupsPanel.setLayout(new BoxLayout(markupsPanel, BoxLayout.PAGE_AXIS));

    for (int i = 0; i < review.getNounPhrases().size(); ++i) {
        JScrollPane newMarkupPanel = newMarkupPanel(review.getNounPhrases().get(i), reviewElement);
        markupsPanel.add(newMarkupPanel);
    }

    JScrollPane scrollMarkupsPanel = new JScrollPane(markupsPanel);

    //Add Dimension for scrolling
    Dimension curScreenDimen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    scrollMarkupsPanel.setPreferredSize(new Dimension((int) curScreenDimen.getWidth() - 50, 400));

    reviewPanel.add(scrollMarkupsPanel);

    //MODEL
    reviewElement.reviewTextArea = reviewContentTxtArea;
    reviewElements.add(reviewElement);

    reviewPanel.add(new JSeparator(SwingConstants.HORIZONTAL));

    reviewPanel.add(Box.createVerticalStrut(20));

    JScrollPane scrollReviewPanel = new JScrollPane(reviewPanel);

    return scrollReviewPanel;
}

From source file:net.sf.jabref.openoffice.StyleSelectDialog.java

private void displayDefaultStyle(boolean authoryear) {
    try {/*from w w w  .j ava  2 s . co  m*/
        // Read the contents of the default style file:
        URL defPath = authoryear ? JabRef.class.getResource(OpenOfficePanel.DEFAULT_AUTHORYEAR_STYLE_PATH)
                : JabRef.class.getResource(OpenOfficePanel.DEFAULT_NUMERICAL_STYLE_PATH);
        BufferedReader r = new BufferedReader(new InputStreamReader(defPath.openStream()));
        String line;
        StringBuilder sb = new StringBuilder();
        while ((line = r.readLine()) != null) {
            sb.append(line);
            sb.append('\n');
        }

        // Make a dialog box to display the contents:
        final JDialog dd = new JDialog(diag, Localization.lang("Default style"), true);
        JLabel header = new JLabel(
                "<html>" + Localization.lang("The panel below shows the definition of the default style.")
                //+"<br>"
                        + Localization.lang(
                                "If you want to use it as a template for a new style, you can copy the contents into a new .jstyle file")
                        + "</html>");

        header.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        dd.getContentPane().add(header, BorderLayout.NORTH);
        JTextArea ta = new JTextArea(sb.toString());
        ta.setEditable(false);
        JScrollPane sp = new JScrollPane(ta);
        sp.setPreferredSize(new Dimension(700, 500));
        dd.getContentPane().add(sp, BorderLayout.CENTER);
        JButton okButton = new JButton(Localization.lang("OK"));
        ButtonBarBuilder bb = new ButtonBarBuilder();
        bb.addGlue();
        bb.addButton(okButton);
        bb.addGlue();
        bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        dd.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
        okButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                dd.dispose();
            }
        });
        dd.pack();
        dd.setLocationRelativeTo(diag);
        dd.setVisible(true);
    } catch (IOException ex) {
        LOGGER.warn("Problem showing default style", ex);
    }
}

From source file:Main.java

public Main() {
    JPanel panel = new JPanel();
    BoxLayout boxLayout = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
    panel.setLayout(boxLayout);//from ww  w .java2s .  co  m
    for (int i = 0; i < 40; i++) {
        panel.add(new JButton("Button " + i));
    }
    buttons = panel.getComponents();
    activeComponent = buttons[index];
    final JScrollPane scroll = new JScrollPane(panel);

    Timer timer = new Timer(500, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ((JButton) activeComponent).setForeground(Color.BLACK);
            if (index >= buttons.length - 1) {
                index = 0;
            } else {
                index++;
            }
            activeComponent = buttons[index];
            ((JButton) activeComponent).setForeground(Color.red);
            setView(scroll, activeComponent);
            System.out.println(((JButton) activeComponent).getActionCommand());
        }
    });
    timer.start();

    scroll.setPreferredSize(new Dimension(200, 300));
    JFrame frame = new JFrame();
    frame.add(scroll);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}