Error with - addStylesToDocument(doc); please help

Hello, this is my unfinished code for a simple program I am writing. Basically I have a menu and buttons, and am looking to add a JTextPane. I think I have all the code there, except when compiling I am having an error with line addStylesToDocument(doc); if I comment this out then nothing happens but the program runs as normal (before I added the JTextPane code) the error I am getting is "non-static method addStylesToDocument(javax.swing.text.StyledDocument) cannot be referenced from a static context" this makes a little sence to me but not enough to be able to correct it as I am pretty much a beginner...
If anyone has any suggestions to fix this I would appreciate your input.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class ShoppingCart extends JPanel
                        implements ActionListener {
    protected JButton bapple, borange, bbanana, bstrawberry, blemon, bgrape, b7, b8, b9, b10;
    public JMenuBar createMenuBar() {
     JMenuBar menuBar;
     JMenu menu, submenu;
     JMenuItem menuItem;
     JRadioButtonMenuItem rbMenuItem;
     JCheckBoxMenuItem cbMenuItem;
menuBar = new JMenuBar();
menuBar.setBackground(Color.white);
      menu = new JMenu("A Menu");
      menu.setBackground(Color.white);
        menu.setMnemonic(KeyEvent.VK_A);
        menu.getAccessibleContext().setAccessibleDescription(
                "The only menu in this program that has menu items");
        menuBar.add(menu);
      //a group of JMenuItems
      menuItem = new JMenuItem("A text-only menu item",
                                 KeyEvent.VK_T);
        //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
         menuItem.setBackground(Color.white);
         menuItem.setAccelerator(KeyStroke.getKeyStroke(
            KeyEvent.VK_1, ActionEvent.ALT_MASK));
       menuItem.getAccessibleContext().setAccessibleDescription(
       "This doesn't really do anything");
        menu.add(menuItem);
        ImageIcon icon = createImageIcon("/orange.gif");
        menuItem = new JMenuItem ("Both text and icon", icon);
        menuItem.setMnemonic(KeyEvent.VK_B);
        menuItem.setBackground(Color.white);
      menu.add(menuItem);
      menuItem = new JMenuItem(icon);
      menuItem.setMnemonic(KeyEvent.VK_D);
      menuItem.setBackground(Color.white);
      menu.add(menuItem);
      //a group of radio button menu items
      menu.addSeparator();
      ButtonGroup group = new ButtonGroup();
      rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
      rbMenuItem.setSelected(true);
      rbMenuItem.setMnemonic(KeyEvent.VK_R);
      rbMenuItem.setBackground(Color.white);
      group.add(rbMenuItem);
      menu.add(rbMenuItem);
      //a group if check box menu items
      menu.addSeparator();
      cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
      cbMenuItem.setMnemonic(KeyEvent.VK_C);
      cbMenuItem.setBackground(Color.white);
      menu.add(cbMenuItem);
      cbMenuItem = new JCheckBoxMenuItem("Another one");
      cbMenuItem.setMnemonic(KeyEvent.VK_H);
      cbMenuItem.setBackground(Color.white);
      menu.add(cbMenuItem);
      //a submenu
      menu.addSeparator();
      submenu = new JMenu("A submenu");
      submenu.setBackground(Color.white);
      submenu.setMnemonic(KeyEvent.VK_S);
      menuItem = new JMenuItem("An  item in the submenu");
      menuItem.setAccelerator(KeyStroke.getKeyStroke(
      KeyEvent.VK_2, ActionEvent.ALT_MASK));
      menuItem.setBackground(Color.white);
      submenu.add(menuItem);
      menuItem = new JMenuItem("Another item");
      menuItem.setBackground(Color.white);
      submenu.add(menuItem);
      menu.add(submenu);
      //Build second menu in the menu bar
      menu = new JMenu("Another Menu");
      menu.setBackground(Color.white);
      menu.setMnemonic(KeyEvent.VK_N);
      menu.getAccessibleContext().setAccessibleDescription(
      "This menu does nothing");
      menuBar.add(menu); 
return menuBar;
    public ShoppingCart() {
        ImageIcon appleButtonIcon = createImageIcon("/apple.gif");
        ImageIcon orangeButtonIcon = createImageIcon("/orange.gif");
        ImageIcon bananaButtonIcon = createImageIcon("/banana.gif");
        ImageIcon strawberryButtonIcon = createImageIcon("/strawberry.gif");
        ImageIcon lemonButtonIcon = createImageIcon("/lemon.gif");
        ImageIcon grapeButtonIcon = createImageIcon("/grape.gif");
        bapple = new JButton(null,  appleButtonIcon);
        bapple.setVerticalTextPosition(AbstractButton.CENTER);
        bapple.setBackground(Color.white);
        bapple.setHorizontalTextPosition(AbstractButton.LEADING);
        bapple.setMnemonic(KeyEvent.VK_D);
        bapple.setActionCommand("apple");
        borange = new JButton(null, orangeButtonIcon);
        borange.setVerticalTextPosition(AbstractButton.BOTTOM);
        borange.setBackground(Color.white);
        borange.setHorizontalTextPosition(AbstractButton.CENTER);
        borange.setMnemonic(KeyEvent.VK_M);
        borange.setActionCommand("orange");
        bbanana = new JButton(null, bananaButtonIcon);
        bbanana.setBackground(Color.white);
        bbanana.setMnemonic(KeyEvent.VK_E);
        bbanana.setActionCommand("banana");
        bstrawberry = new JButton(null,  strawberryButtonIcon);
        bstrawberry.setVerticalTextPosition(AbstractButton.CENTER);
        bstrawberry.setBackground(Color.white);
        bstrawberry.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
        bstrawberry.setActionCommand("strawberry");
        blemon = new JButton(null,  lemonButtonIcon);
        blemon.setBackground(Color.white);
        blemon.setVerticalTextPosition(AbstractButton.CENTER);
        blemon.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
        blemon.setActionCommand("lemon");
        bgrape = new JButton(null,  grapeButtonIcon);
        bgrape.setBackground(Color.white);
        bgrape.setVerticalTextPosition(AbstractButton.CENTER);
        bgrape.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
        bgrape.setActionCommand("grape");
        /*b7 = new JButton(null,  leftButtonIcon);
        b7.setVerticalTextPosition(AbstractButton.CENTER);
        b7.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
        b8 = new JButton(null,  leftButtonIcon);
        b8.setVerticalTextPosition(AbstractButton.CENTER);
        b8.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
        b9 = new JButton(null,  leftButtonIcon);
        b9.setVerticalTextPosition(AbstractButton.CENTER);
        b9.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
        b10 = new JButton(null,  leftButtonIcon);
        b10.setVerticalTextPosition(AbstractButton.CENTER);
        b10.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
        //Listen for actions on buttons
        bapple.addActionListener(this);
        borange.addActionListener(this);
        bbanana.addActionListener(this);
        bstrawberry.addActionListener(this);
        blemon.addActionListener(this);
        bgrape.addActionListener(this);
        bapple.setToolTipText("Apple.");
        borange.setToolTipText("Orange.");
        bbanana.setToolTipText("Banana.");
        bstrawberry.setToolTipText("Strawberry.");
        blemon.setToolTipText("Lemon.");
        bgrape.setToolTipText("Grape.");
       /* b7.setToolTipText("7");
        b8.setToolTipText("8");
        b9.setToolTipText("9");
        b10.setToolTipText("10");
        //Add Components to this container, using the default FlowLayout.
        add(bapple);
        add(borange);
        add(bbanana);
        add(bstrawberry);
        add(blemon);
        add(bgrape);
       /* add(b7);
        add(b8);
        add(b9);
        add(b10);*/
    public void actionPerformed(ActionEvent e) {
        if ("apple".equals(e.getActionCommand())) {
       String  input1 =  JOptionPane.showInputDialog( "How many apples would you like to purchase?" );
        int  number1 = Integer.parseInt( input1 );
         if ("orange".equals(e.getActionCommand())) {
       String  input2 =  JOptionPane.showInputDialog( "How many oranges would you like to purchase?" );
       int  number2 = Integer.parseInt( input2 );
           if ("banana".equals(e.getActionCommand())) {
       String  input3 =  JOptionPane.showInputDialog( "How many bananas would you like to purchase?" );
       int  number3 = Integer.parseInt( input3 );
         if ("strawberry".equals(e.getActionCommand())) {
       String  input4 =  JOptionPane.showInputDialog( "Enter weight of strawberries : " );
       int  number4 = Integer.parseInt( input4 );
         if ("lemon".equals(e.getActionCommand())) {
       String  input5 =  JOptionPane.showInputDialog( "How many lemons would you like to purchase?" );
       int  number5 = Integer.parseInt( input5 );
         if ("grape".equals(e.getActionCommand())) {
       String  input6 =  JOptionPane.showInputDialog( "Enter weight of grapes : " );
       int  number6 = Integer.parseInt( input6 );
    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = ShoppingCart.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
    private static void createAndShowGUI() {
//Create and set up the window.
        JFrame frame = new JFrame("Shopping Cart");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        ShoppingCart newContentPane = new ShoppingCart();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        newContentPane.setBackground(Color.white);
       frame.setJMenuBar(newContentPane.createMenuBar());
        //Display the window.
        frame.pack();
        frame.setVisible(true);
        String[] initString =
        { /* ...  fill array with initial text  ... */ };
        String[] initStyles =
        { /* ...  fill array with names of styles  ... */ };
        JTextPane textPane = new JTextPane();
        StyledDocument doc = textPane.getStyledDocument();
        addStylesToDocument(doc);
        //Load the text pane with styled text.
        try {
        for (int i=0; i < initString.length; i++) {
        doc.insertString(doc.getLength(), initString,
doc.getStyle(initStyles[i]));
} catch (BadLocationException ble) {
System.err.println("Couldn't insert initial text into text pane.");
}protected void addStylesToDocument (StyledDocument doc) {
Style def=new StyleContext ().getStyle (StyleContext.DEFAULT_STYLE);
Style heading = doc.addStyle ("bold", null);
StyleConstants.setFontFamily (heading, "SansSerif");
StyleConstants.setBold (heading, true);
StyleConstants.setFontSize (heading,30);
// * The next 3 don't work if that line is commented out
StyleConstants.setAlignment (heading, StyleConstants.ALIGN_CENTER);
StyleConstants.setSpaceAbove (heading, 10);
StyleConstants.setSpaceBelow (heading, 10);
public static void main() {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();

CPie wrote:
o..k.
I see that you have run out of helpfulness for this session, What the ....? I just told you to add your jtextfield to a jpanel or some other visible component to be seen.
it is getting late here I will take my business elsewhere tomorrow rather than waiting up for a response which shows you realllly need to find something better to do! And thanks for the help earlier. That was actually useful whereas this wasn't, I'm sure you knew that already,You know that we are all volunteers here. Any time spent here helping you is time away from our friends and families. A little more appreciation is definitely in order or go somewhere else and pay for your help.

Similar Messages

  • Error with spring layout -please help me

    hi ppl..
    i had written a piece of code...in which i used spring layout....but it was giving the following error...
    putConstraints(java.awt.Component,javax.swing.SpringLayout.putConstraints) in javax.swing.SpringLayout cannot be applied to putConstraints(java.lang.String,javax.swing.JPanel,int,int,java.lang.String,java.awt.Container)
    The piece of code tat gave the error was
    layout.putConstraints(SpringLayout.WEST,panel1,5, SpringLayout.WEST,contentPane);
    layout.putConstraints(SpringLayout.NORTH,panel1,5,
    SpringLayout.NORTH,contentPane);
    where panel1 is (JPanel) and contentPane is (container)
    please help me....      
    delete

    putConstraints(...)The correct method should be putConstraint(...).

  • Error with SQLServer-JDBC(PLease Help)

    Hello,
    I use before Oracle with Java, but it's first time when I use MS SQL Server, and I made this litle programm Just I want to connect to the Data base, and I get error when I run the programm
    Here you have the file :
    import com.microsoft.jdbc.sqlserver.*;
    import java.sql.*;
    import java.io.*;
    class JDBC_Connect
    public static void main(String args[])
    Connection connexion = null;
    Statement requete = null;
    ResultSet resultSet;
    int i = 1;
    String req1 = "SELECT Name FROM Test";
    try
    String strClassName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
    String strUrl = "jdbc:microsoft:sqlserver://localhost:1433;"
    + "user=sa; DatabaseName=VJ";
    Class.forName(strClassName);
    connexion = DriverManager.getConnection(strUrl);
    requete = connexion.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    resultSet= requete.executeQuery(req1);
    while(resultSet.next())
    System.out.println( resultSet.getString(1));
    i++;
    catch(ClassNotFoundException e) {
    System.err.println("ERREUR : Driver manquant.");
    e.printStackTrace();
    catch(SQLException se) {
    System.out.println("ERREUR SQL : !" + se);
    and here you have the Error that I get
    ERREUR SQL : ! Java.sql.SQLEXception: [Microsoft][SQLServer 2000 Driver for JDBC]
    [SQLServer]Invalid object name 'Test'
    and Test is the name of the Table
    Please If you have an idea about, response my THread, I really need your Help.
    Thanks in advance for your answer.
    Best regards.

    Hi,
    1. When i write the connetion string "con1=DriverManager.getConnection("jdbc:microsoft:sqlserver://ServerName:1433;*Database*=dmo1o2d",user,password);
    Then give message that Connetion is successful. But i put DatabaseName instead of Databse then give error *"java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot open database requested in login 'testcq'*. Login fails.
    2. if i run query like this select * from testcq.sa.test then gives *error "Msg 208, Level 16, State 1, Line 1*
    Invalid object name 'testcq.sa.test'." from MS SQL server management studio
    tescq is Databse name, sa is loging name in MS SQL server mangement stidio to connet to server. test is table name.
    3. if i run query like this select * from testcq.dbo.test then gives all row from MS SQL mangement Studio. But when i rtyr to
    run from java code gives erro "j*ava.sql.SQLException: [Microsoft][SQLServer 2000 Driver for*   
    *   JDBC][SQLServer]Invalid object name 'testcq.dbo.test*'.
    I don't understand where the problem is. It's either in database or in table...all the code, table,database are fine..
    Kindly do needful .....bcoz so many days i m working with this....

  • ERROR with Flash Player Please help!!

    My Roomate was looking at the programs under control panel and well clicked on one of the flash player components and next thing I know it is uninstalled...
    My game chat will not work or sign on due to this and I have tryed everything I can think of but I dont know what I need to install or do to fix this.
    The error I got was:( sorry I do not kow how to do screen shots)
    Adobe Flash Player 10
    An action Script error has ccurred.
    Error.Error#2134: Cannot create SharedObject
                               at flash.net::SharedObject$/getlocal()
                               at njChat_fla::MainTimeline/frame1()
    Please if any one can help with this it would be awesome!

    A few questions:
    what is your operating system & version (also, 32-bit or 64-bit)?
    what is your web browser & version (also, in case of Internet Explorer, 32-bit or 64-bit)?
    what is your Flash Player version (see http://www.adobe.com/software/flash/about/)?
    The error message you listed usually shows a problem of the web application, not on your side.  Unless you have the Flash Player debug version installed.  What does Add/Remove Programs list under Adobe Flash Player?

  • Error with IFRAME portlet - please help!

    We have a portlet that renders in an IFRAME. It has stopped working, and this is the error thrown by the portal. Any help will be rewarded with 1 million dollars cash money! ;-)
    <!--Extended Error Message: A user [Administrator] with ID [1]failed to access URL [http://portal50dev.cei.cox.com:80/portal/server.pt/gateway/PTARGS_0_1_365_201_0_43/http;/portal50dev.cei.cox.com/gadgets/CEI/Custom/General/IndustryNews/gadget.aspx]Error info: [-2147205086: Cannot open page -201 because this page is not owned by the current community.] at com.plumtree.server.CIPTGadgetGateway.GetContent(Object vAppDataStateObject, String vContentID, Int32 vObject, Int32 nClassID, Int32 nPageID, Int32 nCommunityID, String bstrUserInterface, Int32 lMode, Boolean bReturnAllGadgets) at com.plumtree.portalpages.browsing.gateway.GatewayControl.CheckActionSecurityAndExecute(XPHashtable arguments) in C:\UI Source Code\portalpages\dotnet\prod\src\com\plumtree\portalpages\browsing\gateway\GatewayControl.cs:line 158-->

    Jason,
    Please provide add'l background data on this portlet.
    - Did it work previously, and what has changed since then?
    - Does it call data from other portlets?
    (That may include results that the community hosting the 'iframe' based portlet does not have security rights for view access).

  • HT5676 my macpro (10.6.8) refused to install wireless printer (canon pixma MG4260). Whenever i tried to install, it keeps saying 'internal error number 12'. Please help!! and what does internal error got to do with installing a printer?

    my macbook pro (10.6.8) refused to install wireless printer (canon pixma MG4260). Whenever i tried to install, it keeps saying 'internal error number 12'. Please help me!! and what does internal error got to do with installing a printer?

    my macbook pro (10.6.8) refused to install wireless printer (canon pixma MG4260). Whenever i tried to install, it keeps saying 'internal error number 12'. Please help me!! and what does internal error got to do with installing a printer?

  • I have apple id but in this week i see this error : you must verify your payment info befor you can make purchases. please help me. i have not credit card but i buying apps with gift card. please help me

    i have apple id but in this week i see this error : you must verify your payment info befor you can make purchases. please help me. i have not credit card but i buying apps with gift card. please help me

    Why do you keep making multiple posts with this issue? You have now posted it three times in the last hour and have two different people helping you in two different threads!
    https://discussions.apple.com/message/18606895
    https://discussions.apple.com/message/18606685
    This is bad internet manners.

  • My compouter (PC) no longer recognizes my ipod (4th gen), it "sees" an unknowndevice and gives me error code 43.  Please help.

    My compouter (PC) no longer recognizes my ipod (4th gen), it "sees" an unknowndevice and gives me error code 43.  Please help.

    Check for hardware issues
    Try to restore your iOS device two more times while connected with a cable, computer, and network you know are good. Also, confirm your security software and settings are allowing communication between your device and update servers. If you still see the alert when you update or restore, contact Apple support.
    Common errors: 1, 10-47, 1002, 1011, 1012, 1014, 1000-1020.
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar                                      

  • My Ipod wont Sync with ITunes! Please Help!

    My Ipod wont Sync with ITunes! Please Help! I have the latest version of Itunes, but my ipod will not sync with my laptop. The diagnostic test has no answers and says everything is normal. When i try to sync, it says "an unknown error occurred (-39)". Any suggestions?

    check for any viruses

  • HT4623 my voice call services is not working with cellular network...only works fine with wifi..please help?

    my voice call services is not working with cellular network...only works fine with wifi..please help?

    Since you have already done some sort of reset on your Airport Express, you might as well make sure it was a "hard reset" - follow the instructions for a hard reset found at:
    http://docs.info.apple.com/article.html?artnum=108044
    Since your Mac is running Leopard, you need to configure the Airport Express using the Airport Utility found in the Applictions->Utilities folder. You cannot install the old software that was supplied on the CD you got with the Airport Express.
    In future - if you do something bad with network settings on your Mac, do NOT try to fix it with the Airport Utility. The Airport Utility is only used to configure the Airport Express - and since the problem you have created is on the Mac and not the Airport Express, there is no need to be using the Airport Utility and especially there is no need to be resetting the Airport Express.

  • When i am trying to restore backup to my iphone, its coming up that back is not compatible with iphone. Please help me restore backup.

    Hi
    When i am trying to restore backup to my iphone, its coming up backup is not compatible with iphone. Please help me restore.
    Thanks
    Mandy

    From the article that the question was posted from:
    Error 1611
    This error typically occur when security software interferes with the restore and update process. Follow Troubleshooting security software issues to resolve this issue. In rare cases, this error may be a hardware issue. If the errors persist on another computer, the device may need service.
    Try reading the solutions you find in the future and follow them.

  • TS3694 i think itunes  has removed my iphone software. because now not showing home screen. when i tried to restore my phone there generated an error no is 1015. please help me how can i recover my iphone again?

    i think itunes  has removed my iphone software. because now not showing home screen. when i tried to restore my phone there generated an error no is 1015. please help me how can i recover my iphone again?

    From the article which you posted your question from:
    Errors related to downgrading iOS
    The required resource cannot be found: This alert message occurs when your device has a newer version of iOS than what is available in iTunes. When troubleshooting a device that presents this alert message, go to Settings > General > About and check the version of iOS on the device. If it is newer than the latest released iOS version, the device may have a prerelease developer version of iOS installed.   Installing an older version of iOS over a newer version is not supported.
    Error 1015: This error is typically caused by attempts to downgrade the iPhone, iPad, or iPod touch's software. This can occur when you attempt to restore using an older .ipsw file. Downgrading to a previous version is not supported. To resolve this issue, attempt to restore with the latest iPhone, iPad, or iPod touch software available from Apple. This error can also occur when an unauthorized modification of the iOS has occurred and you are now trying to restore to an authorized, default state.

  • HT5642 Unable to download app this time error while downloading app please help!!!

    when i download some app from apps store i get the following error
    "Unable to download app this time error while downloading app" please help!!!
    i ve tried these Things but
    didnt workout yet
    1) i tried hard reset
    2)i tried logout/login Itune & appstore
    3)Connected to pc and rest setting Network and Full Rest
    all of no use... i dont want to update my softwre from IOS 6.0
    Plx help!1

    Hey Prahaladvatsan,
    Thanks for the question. If I understand correctly, there is a blank app icon on the home screen. It looks like you have already done some troubleshooting. I would recommend that you read these articles, they may be helpful in troubleshooting your issue.
    Restart or reset your iPhone, iPad, or iPod touch - Apple Support
    Back up and restore your iPhone, iPad, or iPod touch using iCloud or iTunes - Apple Support
    Thanks for using Apple Support Communities.
    Have a good one,
    Mario

  • IPhone 4s not being recognized and cannot be activated for service--what does this mean? I can't sync with iTunes. Please help

    iPhone not being recognized and cannot be activated for service--what does this mean? I can't sync with iTunes. Please help.
    When I connect iPhone to USB iTunes is giving me the above message. Please advise if you know the fix.
    Thanks,
    Lina1116

    did you find a fix?

  • My iphone is not charging or showing in my computer. but its getting charged via wall apple charger.. Not able to connect with itunes.. please help.... :(

    My iphone is not charging or showing in my computer. but its getting charged via wall apple charger.. Not able to connect with itunes.. please help....

    No it doesn't. Sometimes it make a sound that it should when connecting but that is it. Never actually charges or syncs. And it is a brand new cord.

Maybe you are looking for