Example usage for javax.swing JScrollBar setPreferredSize

List of usage examples for javax.swing JScrollBar setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JScrollBar 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:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Vector<Vector<String>> rowData = new Vector<Vector<String>>();
    Vector<String> columnName = new Vector<String>(Arrays.asList("Column 1"));
    for (int i = 0; i < 2000; i++) {
        rowData.add(new Vector<String>(Arrays.asList(Integer.toString(i))));
    }/*from  w ww. j av a  2  s . c om*/
    JTable table = new JTable(rowData, columnName);
    JScrollPane scrollPane = new JScrollPane(table);
    JScrollBar vertical = scrollPane.getVerticalScrollBar();
    vertical.setPreferredSize(new Dimension(0, 0));
    f.add(scrollPane);
    f.pack();
    f.setVisible(true);
    JViewport view = scrollPane.getViewport();
    Component[] components = view.getComponents();
    for (int i1 = 0; i1 < components.length; i1++) {
        if (components[i1] instanceof JTable) {
            System.out.println("got");
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();

    JPanel main = new JPanel(new GridLayout(2, 1));
    JPanel scrollBarPanel = new JPanel();
    final JScrollBar scrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 48, 0, 255);
    int height = scrollBar.getPreferredSize().height;
    scrollBar.setPreferredSize(new Dimension(175, height));
    scrollBarPanel.add(scrollBar);/*from w w w.  j a v  a2  s . co m*/
    main.add(scrollBarPanel);

    JPanel sliderPanel = new JPanel();
    final JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 255, 128);
    slider.setMajorTickSpacing(48);
    slider.setMinorTickSpacing(16);
    slider.setPaintTicks(true);
    sliderPanel.add(slider);
    main.add(sliderPanel);

    frame.add(main, BorderLayout.CENTER);

    scrollBar.addAdjustmentListener(new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("JScrollBar's current value = " + scrollBar.getValue());
        }
    });

    slider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            System.out.println("JSlider's current value = " + slider.getValue());
        }
    });

    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
}

From source file:MainClass.java

MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(300, 50));
    JScrollBar jsb;
    jsb = new JScrollBar(Adjustable.HORIZONTAL, 0, 1, 0, 100);
    jsb.setPreferredSize(new Dimension(200, 20));
    p.add(jsb);//w  w  w  .j av a2 s  . co  m

    getContentPane().add(p);

    pack();
    setVisible(true);
}

From source file:v800_trainer.JCicloTronic.java

public void ChangeModel() {

    setCursor(new Cursor(Cursor.WAIT_CURSOR));
    if (Hauptfenster != null)
        Hauptfenster.setSelectedIndex(0);
    DataProperty = new java.util.Properties();

    jTableaccess = Datentabelle;/*from w w  w . j  av  a 2 s.c  om*/
    String Filename = "";
    String PlaceHolder = "          ";
    File path = new File(Properties.getProperty("data.dir"));
    final String[] names = { "Datum", "Strecke", "Hhenmeter", "Zeit", "Titel" };

    String[] list = path.list(new DirFilter("_Tour.cfg"));

    RowCount = 0;
    int Anzahlcfg = 0;
    if (list != null)
        Anzahlcfg = list.length;
    if (Anzahlcfg == 0) {
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        return;
    }

    Object datab[] = new Object[8];
    ArrayList<Object[]> data_list = new ArrayList<Object[]>();

    String hmString = "";
    DecimalFormat form = new DecimalFormat("0");//Format ohne Kommastelle
    int j = 0;
    for (int i = 0; i < Anzahlcfg; i++) { //berprfen ob Hhenmeter eingetragen sind - ansonsten ermitteln (gilt fr neue Dateien)
        Filename = path.getPath() + SystemProperties.getProperty("file.separator") + list[i];
        DataProperty = new java.util.Properties();
        try {

            BufferedInputStream in = new BufferedInputStream(new FileInputStream(Filename));
            DataProperty.load(in);
            in.close();
            // prfen ob Datei gezeigt werden soll - Visible = 0 wenn Datei gelscht wurde
            if (!DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1"))
                continue;
            // wenn keine Hhenmeter eingetragen wurden (Erstaufruf) dann Hhenmeter ermitteln
            if (DataProperty.getProperty("Hoehenmeter", "novalue").equalsIgnoreCase("novalue")
                    && DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1")
                    && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) {
                JTourData Dummydata = new JTourData(Filename.substring(0, Filename.lastIndexOf('.')), this);
                DataProperty.setProperty("Hoehenmeter", form.format(Dummydata.ges_Hoehep));
                try {
                    Ausgabedatei = new FileOutputStream(Filename);
                    DataProperty.store(Ausgabedatei,
                            "Tour Eigenschaften: " + DataProperty.getProperty("Jahr")
                                    + DataProperty.getProperty("Monat") + DataProperty.getProperty("Tag")
                                    + DataProperty.getProperty("Stunde") + DataProperty.getProperty("Minute"));
                    Ausgabedatei.close();
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, " Fehler bei Speichern der DataProperty in ChangeModel",
                            "Achtung!", JOptionPane.ERROR_MESSAGE);

                }
            }

            try {
                if (Integer.parseInt(DataProperty.getProperty("Visible", "1")) == 1
                        && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) {

                    datab[0] = new String("  " + DataProperty.getProperty("Tag", "11") + "."
                            + DataProperty.getProperty("Monat", "11") + "."
                            + DataProperty.getProperty("Jahr", "1111"));
                    datab[1] = PlaceHolder.substring(0, 9 - DataProperty.getProperty("Strecke", "0").length())
                            + DataProperty.getProperty("Strecke", "0") + " ";
                    //                      data[j][1] = new String(DataProperty.getProperty("Strecke") + " ");
                    datab[2] = new String(
                            "  " + HMS(java.lang.Integer.parseInt(DataProperty.getProperty("Dauer", "0"))));
                    datab[3] = new String(DataProperty.getProperty("Titel", "---"));
                    datab[4] = new String(DataProperty.getProperty("Jahr", "1111") + "."
                            + DataProperty.getProperty("Monat", "11") + "."
                            + DataProperty.getProperty("Tag", "11") + "."
                            + DataProperty.getProperty("Stunde", "12") + "."
                            + DataProperty.getProperty("Minute", "59"));
                    datab[5] = new String(Filename.substring(0, Filename.lastIndexOf('.')));
                    datab[6] = new String(DataProperty.getProperty("Typ", "unbekannt"));
                    hmString = "" + (int) Float.parseFloat(DataProperty.getProperty("Hoehenmeter", "0"));
                    datab[7] = PlaceHolder.substring(0, 9 - hmString.length()) + hmString + " ";
                    data_list.add(datab.clone());
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Fehler beim Erstellen der Datenliste " + e + " " + j,
                        "Achtung!", JOptionPane.ERROR_MESSAGE);
            }

        } catch (Exception e) {
            System.out.println(
                    "NEW IO-Fehler bei " + path.getPath() + SystemProperties.getProperty("file.separator")
                            + list[i] + "\n " + e + "   " + e.getLocalizedMessage() + "--File deleted");
            e.printStackTrace();
            JOptionPane.showMessageDialog(null,
                    "Fehler beim Einlesen eines cfg Files " + path.getPath()
                            + SystemProperties.getProperty("file.separator") + list[i] + "\n  wurde gelscht!",
                    "Achtung!", JOptionPane.ERROR_MESSAGE);
            File deletefile = new File(
                    path.getPath() + SystemProperties.getProperty("file.separator") + list[i]);
            if (deletefile.exists())
                deletefile.delete();
            ChangeModel();
        }
    }

    TableModel dataModel = new AbstractTableModel() {

        public int getColumnCount() {
            return names.length;
        }

        @Override
        public String getColumnName(int column) {
            return names[column];
        }

        @Override
        public int getRowCount() {
            return data_list.size();
        }

        @Override
        public Object getValueAt(int row, int col) {

            Object data[] = new Object[8];
            data = data_list.get(row);
            return data[col];
        }

        @Override
        public void setValueAt(Object Ob, int row, int col) {
            Object data[] = new Object[8];
            data = data_list.get(row);
            data[col] = Ob;
            data_list.set(row, data);

        }
    };

    sorter = new TableSorter(dataModel);
    DatumColumn = new TableColumn(0);
    DatumColumn.setHeaderValue(names[0]);
    DatumColumn.setResizable(false);
    StreckeColumn = new TableColumn(1);
    StreckeColumn.setHeaderValue(names[1]);
    StreckeColumn.setResizable(false);
    HoeheColumn = new TableColumn(7);
    HoeheColumn.setHeaderValue(names[2]);
    HoeheColumn.setResizable(false);
    ZeitColumn = new TableColumn(2);
    ZeitColumn.setHeaderValue(names[3]);
    ZeitColumn.setResizable(false);
    NotizColumn = new TableColumn(3);
    NotizColumn.setHeaderValue(names[4]);

    DatumColumn.setMinWidth((int) 80 * FontSize / 12);
    StreckeColumn.setMinWidth((int) 65 * FontSize / 12);
    HoeheColumn.setMinWidth((int) 75 * FontSize / 12);
    ZeitColumn.setMinWidth((int) 75 * FontSize / 12);
    NotizColumn.setMinWidth((int) 75 * FontSize / 12);
    NotizColumn.setPreferredWidth((int) 75 * FontSize / 12 + 1000);
    DefaultTableCellRenderer TableCell = new DefaultTableCellRenderer();
    TableCell.setHorizontalAlignment(JLabel.CENTER);
    HoeheColumn.setCellRenderer(TableCell);
    StreckeColumn.setCellRenderer(TableCell);
    DatumColumn.setCellRenderer(TableCell);
    ZeitColumn.setCellRenderer(TableCell);
    HoeheColumn.setHeaderRenderer(TableCell);
    StreckeColumn.setHeaderRenderer(TableCell);
    DatumColumn.setHeaderRenderer(TableCell);
    ZeitColumn.setHeaderRenderer(TableCell);
    NotizColumn.setHeaderRenderer(TableCell);

    DefaultTableColumnModel FileTableModel = new DefaultTableColumnModel();
    FileTableModel.addColumn(DatumColumn);
    FileTableModel.addColumn(StreckeColumn);
    FileTableModel.addColumn(HoeheColumn);
    FileTableModel.addColumn(ZeitColumn);
    FileTableModel.addColumn(NotizColumn);

    Datentabelle.setModel(sorter);
    Datentabelle.setColumnModel(FileTableModel);
    Datentabelle.setRowHeight(FontSize + 5);
    sorter.addMouseListenerToHeaderInTable(Datentabelle);
    sorter.sortByColumn(0, false);
    Datentabelle.clearSelection();
    SelectionChanged = true;

    JScrollBar verticaldummy = Datenliste_scroll_Panel.getVerticalScrollBar();

    verticaldummy.setPreferredSize(new Dimension(FontSize + 10, FontSize + 10));
    Datenliste_scroll_Panel.setVerticalScrollBar(verticaldummy);

    Update = false;
    Datenliste_Jahr.removeAllItems();
    Datenliste_TourTyp.removeAllItems();
    Auswahl_bersicht.removeAllItems();
    JahrVergleich.removeAllItems();

    InitComboJahr();
    InitComboTyp();

    Update = true;

    if (Datentabelle.getRowCount() != 0) {
        Datentabelle.addRowSelectionInterval(0, 0);
        Datenliste_scroll_Panel.getViewport().setViewPosition(new java.awt.Point(0, 0));
    }

    if (Uebersicht != null) {
        Uebersicht = null;
    }
    jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount());

    repaint();
    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}