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:components.ScrollDemo.java

public ScrollDemo() {
    setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

    //Get the image to use.
    ImageIcon bee = createImageIcon("images/flyingBee.jpg");

    //Create the row and column headers.
    columnView = new Rule(Rule.HORIZONTAL, true);
    rowView = new Rule(Rule.VERTICAL, true);

    if (bee != null) {
        columnView.setPreferredWidth(bee.getIconWidth());
        rowView.setPreferredHeight(bee.getIconHeight());
    } else {/*ww  w .j ava  2s.com*/
        columnView.setPreferredWidth(320);
        rowView.setPreferredHeight(480);
    }

    //Create the corners.
    JPanel buttonCorner = new JPanel(); //use FlowLayout
    isMetric = new JToggleButton("cm", true);
    isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11));
    isMetric.setMargin(new Insets(2, 2, 2, 2));
    isMetric.addItemListener(this);
    buttonCorner.add(isMetric);

    //Set up the scroll pane.
    picture = new ScrollablePicture(bee, columnView.getIncrement());
    JScrollPane pictureScrollPane = new JScrollPane(picture);
    pictureScrollPane.setPreferredSize(new Dimension(300, 250));
    pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black));

    pictureScrollPane.setColumnHeaderView(columnView);
    pictureScrollPane.setRowHeaderView(rowView);

    //Set the corners.
    //In theory, to support internationalization you would change
    //UPPER_LEFT_CORNER to UPPER_LEADING_CORNER,
    //LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and
    //UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER.  In practice,
    //bug #4467063 makes that impossible (in 1.4, at least).
    pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner);
    pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, new Corner());
    pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new Corner());

    //Put it in this panel.
    add(pictureScrollPane);
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}

From source file:components.ScrollDemo2.java

public ScrollDemo2() {
    super(new BorderLayout());

    area = new Dimension(0, 0);
    circles = new Vector<Rectangle>();

    //Set up the instructions.
    JLabel instructionsLeft = new JLabel("Click left mouse button to place a circle.");
    JLabel instructionsRight = new JLabel("Click right mouse button to clear drawing area.");
    JPanel instructionPanel = new JPanel(new GridLayout(0, 1));
    instructionPanel.setFocusable(true);
    instructionPanel.add(instructionsLeft);
    instructionPanel.add(instructionsRight);

    //Set up the drawing area.
    drawingPane = new DrawingPane();
    drawingPane.setBackground(Color.white);
    drawingPane.addMouseListener(this);

    //Put the drawing area in a scroll pane.
    JScrollPane scroller = new JScrollPane(drawingPane);
    scroller.setPreferredSize(new Dimension(200, 200));

    //Lay out this demo.
    add(instructionPanel, BorderLayout.PAGE_START);
    add(scroller, BorderLayout.CENTER);
}

From source file:de.burrotinto.jKabel.dispalyAS.DisplayK.java

@Bean(name = "bearbeitenPanel")
public JPanel getBearbeitenPanel(KabelTypAuswahlAAS kabelTypAuswahlAAS, TrommelAuswahlAAS tommelAAs,
        StreckenAAS streckenAAS, Color background) {

    kabelTypAuswahlAAS.addKabelTypListner(tommelAAs);
    kabelTypAuswahlAAS.addKabelTypListner(streckenAAS);

    tommelAAs.addTrommelListner(streckenAAS);

    JPanel l = new JPanel(new GridLayout(1, 2));
    JPanel all = new JPanel(new GridLayout(1, 2));

    JScrollPane kSP = new JScrollPane(kabelTypAuswahlAAS);
    l.add(kSP);/*from www  .  j  av  a2 s  . c  o  m*/
    l.add(new JScrollPane(tommelAAs));
    all.add(l);
    JScrollPane sc = new JScrollPane(streckenAAS);
    sc.setPreferredSize(new Dimension(740, 740));
    all.add(sc);

    kSP.setOpaque(false);
    sc.setOpaque(false);

    l.setBackground(background);
    kabelTypAuswahlAAS.setBackground(background);
    tommelAAs.setBackground(background);
    streckenAAS.setBackground(background);

    try {
        streckenAAS.setLogo(ImageIO.read(new File(ConfigReader.getInstance().getPath() + "logo.jpg")));
    } catch (IOException e) {
        streckenAAS.setLogo(null);
    }
    all.setBackground(background);
    return all;
}

From source file:com.jdom.util.patterns.mvp.swing.RadioButtonGroupDialog.java

private RadioButtonGroupDialog(Frame frame, Component locationComp, String labelText, String title,
        Collection<String> data, String initialValue, String longValue) {
    super(frame, title, true);

    final JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(this);

    final JButton setButton = new JButton("OK");
    setButton.setActionCommand("OK");
    setButton.addActionListener(this);
    getRootPane().setDefaultButton(setButton);

    ButtonGroup radioButtonGroup = new ButtonGroup();
    for (String option : data) {
        JRadioButton button = new JRadioButton(option);
        if (option.equals(initialValue)) {
            button.setSelected(true);//from w  w  w. j a v  a2  s  .  c o  m
        }
        radioButtonGroup.add(button);
        panel.add(button);
    }

    JScrollPane listScroller = new JScrollPane(panel);
    listScroller.setPreferredSize(new Dimension(250, 80));
    listScroller.setAlignmentX(LEFT_ALIGNMENT);

    JPanel listPane = new JPanel();
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));

    if (!StringUtils.isEmpty(labelText)) {
        JLabel label = new JLabel(labelText);
        label.setText(labelText);
        listPane.add(label);
    }
    listPane.add(Box.createRigidArea(new Dimension(0, 5)));
    listPane.add(listScroller);
    listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(cancelButton);
    buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPane.add(setButton);

    Container contentPane = getContentPane();
    contentPane.add(listPane, BorderLayout.CENTER);
    contentPane.add(buttonPane, BorderLayout.PAGE_END);

    pack();
    setLocationRelativeTo(locationComp);
}

From source file:KeyEventDemo.java

public KeyEventDemo() {
    super(new BorderLayout());

    JButton button = new JButton("Clear");
    button.addActionListener(this);

    typingArea = new JTextField(20);
    typingArea.addKeyListener(this);

    //Uncomment this if you wish to turn off focus
    //traversal. The focus subsystem consumes
    //focus traversal keys, such as Tab and Shift Tab.
    //If you uncomment the following line of code, this
    //disables focus traversal and the Tab events will
    //become available to the key event listener.
    //typingArea.setFocusTraversalKeysEnabled(false);

    displayArea = new JTextArea();
    displayArea.setEditable(false);/*from  ww  w . j  a  va  2  s. com*/
    JScrollPane scrollPane = new JScrollPane(displayArea);
    scrollPane.setPreferredSize(new Dimension(375, 125));

    add(typingArea, BorderLayout.PAGE_START);
    add(scrollPane, BorderLayout.CENTER);
    add(button, BorderLayout.PAGE_END);
}

From source file:events.KeyEventDemo.java

private void addComponentsToPane() {

    JButton button = new JButton("Clear");
    button.addActionListener(this);

    typingArea = new JTextField(20);
    typingArea.addKeyListener(this);

    //Uncomment this if you wish to turn off focus
    //traversal.  The focus subsystem consumes
    //focus traversal keys, such as Tab and Shift Tab.
    //If you uncomment the following line of code, this
    //disables focus traversal and the Tab events will
    //become available to the key event listener.
    //typingArea.setFocusTraversalKeysEnabled(false);

    displayArea = new JTextArea();
    displayArea.setEditable(false);//ww  w. j a  v  a2s  .c  o  m
    JScrollPane scrollPane = new JScrollPane(displayArea);
    scrollPane.setPreferredSize(new Dimension(375, 125));

    getContentPane().add(typingArea, BorderLayout.PAGE_START);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    getContentPane().add(button, BorderLayout.PAGE_END);
}

From source file:TextEditor.java

private void createTextArea() {
    textArea = new JTextArea("some text");
    textArea.setLineWrap(true);//from   w ww . j a  v  a2s . c  o m
    textArea.setWrapStyleWord(true);
    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setPreferredSize(new Dimension(450, 250));
    add(areaScrollPane);
}

From source file:com.googlecode.logVisualizer.chart.StatDevelopmentChartMouseEventListener.java

public void chartMouseClicked(final ChartMouseEvent e) {
    if (e.getEntity() instanceof XYItemEntity) {
        final XYItemEntity entity = (XYItemEntity) e.getEntity();
        final int turnNumber = entity.getDataset().getX(0, entity.getItem()).intValue();

        Turn turn = null;//from www .  j ava2  s  .c o m
        if (logData.isDetailedLog())
            for (final SingleTurn st : logData.getTurnsSpent()) {
                if (st.getTurnNumber() == turnNumber) {
                    turn = st;
                    break;
                }
            }
        else
            for (final TurnInterval ti : logData.getTurnIntervalsSpent())
                if (ti.getEndTurn() == turnNumber) {
                    turn = ti;
                    break;
                }

        EquipmentChange equipment = null;
        if (logData.isDetailedLog())
            equipment = ((SingleTurn) turn).getUsedEquipment();
        final StringBuilder str = new StringBuilder(250);
        str.append("Turn spent in area: " + turn.getAreaName() + "\n");
        if (logData.isDetailedLog())
            str.append("Encounter name: " + ((SingleTurn) turn).getEncounterName() + "\n");
        str.append("Stats gained: " + turn.getStatGain() + "\n");
        if (logData.isDetailedLog()) {
            str.append("Familiar used: " + ((SingleTurn) turn).getUsedFamiliar().getFamiliarName() + "\n\n");
            str.append("Equipment:\n");
            str.append("    Hat: " + equipment.getHat() + "\n");
            str.append("    Weapon: " + equipment.getWeapon() + "\n");
            str.append("    Offhand: " + equipment.getOffhand() + "\n");
            str.append("    Shirt: " + equipment.getShirt() + "\n");
            str.append("    Pants: " + equipment.getPants() + "\n");
            str.append("    Acc1: " + equipment.getAcc1() + "\n");
            str.append("    Acc2: " + equipment.getAcc2() + "\n");
            str.append("    Acc3: " + equipment.getAcc3() + "\n");
            str.append("    FamEquip: " + equipment.getFamEquip() + "\n");
        }
        str.append("\nConsumables used:\n");
        for (final Consumable c : turn.getConsumablesUsed())
            str.append("    " + c + "\n");
        str.append("\nItems dropped:\n");
        for (final Item i : turn.getDroppedItems())
            str.append("    " + i + "\n");

        final JScrollPane text = new JScrollPane(new JTextArea(str.toString()));
        text.setPreferredSize(new Dimension(500, 450));
        JOptionPane.showMessageDialog(null, text, "Information on " + turn, JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:soap.ui.panel.innerCentralPanel.StatsPanel.java

protected void initUI() {
    if (mIndicatorsName.size() != 0) {
        defaultAddComponent(new JLabel(resMan.getString("statsChooseIndicator")), SoapGridbagPanel.END);

        JPanel indicatorsPanel = new JPanel();
        indicatorsPanel.setBackground(Color.WHITE);
        indicatorsPanel.setLayout(new GridLayout(mIndicatorsName.size(), 1));
        mCheckBoxTable = new JCheckBox[mIndicatorsName.size()];
        CheckBoxListener listener = new CheckBoxListener();
        Iterator it = mIndicatorsName.keySet().iterator();
        for (int i = 0; i < mIndicatorsName.size(); i++) {
            String key = (String) it.next();
            mCheckBoxTable[i] = new JCheckBox((String) mIndicatorsName.get(key));
            mCheckBoxTable[i].setName(key);
            mCheckBoxTable[i].setPreferredSize(new Dimension(50, 20));
            mCheckBoxTable[i].setBackground(Color.WHITE);
            mCheckBoxTable[i].addItemListener(listener);
            indicatorsPanel.add(mCheckBoxTable[i]);
        }//from   w  w  w  . jav a 2 s .c  o  m
        JScrollPane scrollPane = new JScrollPane(indicatorsPanel);
        scrollPane.setPreferredSize(new Dimension(140, 65));
        defaultAddComponent(scrollPane, SoapGridbagPanel.END, 1, 0, new Insets(10, 0, 20, 0));

        // add the chart to a panel...
        mChartPanel.setPreferredSize(new Dimension(580, 330));
        defaultAddComponent(new JScrollPane(mChartPanel), SoapGridbagPanel.END);
    }
}

From source file:events.MouseEventDemo.java

public MouseEventDemo() {
    super(new GridLayout(0, 1));
    blankArea = new BlankArea(Color.YELLOW);
    add(blankArea);//from w  w w . j  a  v a 2  s  .  c o m
    textArea = new JTextArea();
    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(200, 75));
    add(scrollPane);

    //Register for mouse events on blankArea and the panel.
    blankArea.addMouseListener(this);
    addMouseListener(this);
    setPreferredSize(new Dimension(450, 450));
    setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
}