2 Replies - 1909 Views - Last Post: 08 November 2008 - 10:16 AM Rate Topic: -----

#1 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

JScrollPane Errors

Posted 08 November 2008 - 08:04 AM

Every time I run Main.java (below) I get these errors:
Exception in thread "main" java.lang.IllegalArgumentException: invalid verticalScrollBarPolicy
at javax.swing.JScrollPane.setVerticalScrollBarPolicy(JScrollPane.java:489)
at javax.swing.JScrollPane.<init>(JScrollPane.java:281)
at ntext.Main.<init>(Main.java:14)
at ntext.Main.main(Main.java:189)

Main.java:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
import java.util.*;
import java.io.*;

public class Main extends JFrame implements 
        ActionListener
{    
    public static JEditorPane editor = new JEditorPane();
    private JScrollPane editorScrollPane = new JScrollPane(editor,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    private JMenuItem editCopy = new JMenuItem();
    private JMenuItem editCut = new JMenuItem();
    private JMenu editMenu = new JMenu();
    private JMenuItem editPaste = new JMenuItem();
    private JMenu fileMenu = new JMenu();
    private JMenuItem fileNew = new JMenuItem();
    private JMenuItem fileOpen = new JMenuItem();
    private JMenuItem fileSave = new JMenuItem();
    private JMenuItem formatFonts = new JMenuItem();
    private JMenu formatMenu = new JMenu();
    private JSeparator jSeparator1 = new JSeparator();
    private JSeparator jSeparator2 = new JSeparator();
    private JMenuBar menuBar = new JMenuBar();
    private JMenuItem quit = new JMenuItem();
    private JMenuItem selectAll = new JMenuItem();
    private JMenuItem timeDate = new JMenuItem();
    
    public static void getTime()
        {
            String time;
        Calendar now = Calendar.getInstance();
        int hour = now.get(Calendar.HOUR_OF_DAY);
        int minute = now.get(Calendar.MINUTE);
        int month = now.get(Calendar.MONTH) + 1;
        int day = now.get(Calendar.DAY_OF_MONTH);
        int year = now.get(Calendar.YEAR);

        String monthName = "";
        switch (month)
        {
            case (1):
                monthName = "January";
                break;
            case (2):
                monthName = "February";
                break;
            case (3):
                monthName = "March";
                break;
            case (4):
                monthName = "April";
                break;
            case (5):
                monthName = "May";
                break;
            case (6):
                monthName = "June";
                break;
            case (7):
                monthName = "July";
                break;
            case (8):
                monthName = "August";
                break;
            case (9):
                monthName = "September";
                break;
            case (10):
                monthName = "October";
                break;
            case (11):
                monthName = "November";
                break;
            case (12):
                monthName = "December";
        }
        time = monthName + " " + day + ", " + year + " " + hour + ":" + minute;
        String text = editor.getText();
        
        if (text == null) {
            editor.setText(time);
        } else {
            editor.setText(text + " " + time);
        }
    }
    public Main() 
    {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setTitle("nText 0.6.0.5 Beta");
        setSize(500, 300);
        setLayout(new BorderLayout());
        
        fileMenu.setText("File");

        fileNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        fileNew.setText("New File");
        fileMenu.add(fileNew);

        fileOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        fileOpen.setText("Open File");
        fileOpen.addActionListener(this);
        fileMenu.add(fileOpen);

        fileSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        fileSave.setText("Save File");
        fileSave.addActionListener(this);
        fileMenu.add(fileSave);
        fileMenu.add(jSeparator1);

        quit.setText("Quit");
        quit.addActionListener(this);
        fileMenu.add(quit);

        menuBar.add(fileMenu);

        editMenu.setText("Edit");

        editCut.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        editCut.setText("Cut");
        editCut.addActionListener(this);
        editMenu.add(editCut);

        editCopy.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        editCopy.setText("Copy");
        editCopy.addActionListener(this);
        editMenu.add(editCopy);

        editPaste.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        editPaste.setText("Paste");
        editPaste.addActionListener(this);
        editMenu.add(editPaste);
        editMenu.add(jSeparator2);

        timeDate.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
        timeDate.setText("Time & Date");
        timeDate.addActionListener(this);
        editMenu.add(timeDate);

        selectAll.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        selectAll.setText("Select All");
        editMenu.add(selectAll);

        menuBar.add(editMenu);

        formatMenu.setText("Format");

        formatFonts.setText("Font...");
        formatMenu.add(formatFonts);

        menuBar.add(formatMenu);

        setJMenuBar(menuBar);
        
        add(editorScrollPane);
        setVisible(true);
    }

    public void actionPerformed(ActionEvent evt) 
    {
        Object source = evt.getSource();
        if (source == fileOpen) {
        new openFile();
        } else if (source == fileNew) {
            editor.setText("");
        } else if (source == fileSave) {
            saveFile.saveFile();
        } else if (source == quit) {
            System.exit(0);
        } else if (source == editCut) {
            editor.cut();
        } else if (source == editCopy) {
            editor.copy();
        } else if (source == editPaste) {
            editor.paste();
        } else if (source == timeDate) {
            getTime();
        } else if (source == formatFonts) {
            // The font changer will be ignored until the syntax highlighter is finished.
        }
}

    public static void main(String args[]) {
        new Main();
    }    
}



Is This A Good Question/Topic? 0
  • +

Replies To: JScrollPane Errors

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: JScrollPane Errors

Posted 08 November 2008 - 10:01 AM

You have them reversed, it is Vertical scroll bar policy first, then the horizontal one. Once you switch them around you will be golden.

:)

This post has been edited by Martyr2: 08 November 2008 - 10:01 AM

Was This Post Helpful? 1
  • +
  • -

#3 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: JScrollPane Errors

Posted 08 November 2008 - 10:16 AM

Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1