Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,163
    Rep Power
    6

    Default Re: nullpointer but text is present

    > how can I resolve the tail part of the string "text=Abadi MT Condensed Extra Bold"?

    Explain that more clearly and you've got yourself a perfectly readable question.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  2. #22
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,008
    Rep Power
    3

    Default Re: nullpointer but text is present

    Imagine your Java application being a diamond necklace. It's made with hundreds of golden wires each with a diamond in it. If you make one huge golden wire and try to put in all the diamonds at once, it will never work and becomes a mess very soon. Instead, make each part of the necklace individually and add them to the necklace.

    My main message here is: Break your requirements down to the basics, make little test-projects and add Swing components to your application when you know how they work.

    Here's an example I cooked up to demonstrate basic use of the JRadioButtonMenuItem. There are lots of fun things you can do with Swing components, so don't think this is the end of the line. This is just the beginning. You should do this for each component you try to use.

    Java Code:
    package forums.swing;
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    public class Menu {
    
        private static JLabel fontLabel;
    
        public static void main(String[] args) {
            JFrame f = new JFrame("JRadioButtonMenuItem test");
    
            JPanel mainContent = new JPanel(new BorderLayout());
            fontLabel = new JLabel();
            mainContent.add(fontLabel);
    
            f.setContentPane(mainContent);
    
            f.setJMenuBar(getMenuBar());
    
            f.setSize(500, 500);
            f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    
        }
    
        public static JMenuBar getMenuBar() {
            JMenuBar bar = new JMenuBar();
    
            JMenu fonts = new JMenu("Fonts");
    
            ActionListener listener = new ActionListener() {
                @Override
                public void actionPerformed(final ActionEvent e) {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            JRadioButtonMenuItem item = (JRadioButtonMenuItem) e.getSource();
                            fontLabel.setText(item.getText());
                        }
                    });
    
                }
            };
    
            String[] availableFontFamilyNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
            for (String availableFontFamilyName : availableFontFamilyNames) {
                JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(availableFontFamilyName);
                menuItem.addActionListener(listener);
                fonts.add(menuItem);
            }
    
            bar.add(fonts);
    
            return bar;
        }
    }
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #23
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: nullpointer but text is present

    Quote Originally Posted by gimbal2 View Post
    Ouch, I would really implore you to just advise people to use the equals() method to compare if two Class instances are the same. Now you have to assume that the OP does not need to be explained that Class object instances are unique within the same classloader, which is why in this particular case it just so happens that using the equality operator magically works while in 99.9% of the cases it won't work for object types and you in fact need to use the equals() method. Its just too much baggage :)
    I don't think it matters for Class instances. If you dynamically load the same class Foo with two different classloaders, instances of Foo loaded by one classloader will not be assignable to references to Foo in classes loaded by the other classloader. In effect, the two Class instances for Foo are different classes to the JVM, even though they were loaded from the same class definition. This is why classloaders delegate to their parents before attempting to load classes themselves.
    Get in the habit of using standard Java naming conventions!

  4. #24
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: nullpointer but text is present

    OP: You are learning how enormously complicated a program can become if you don't follow the MVC pattern.
    Get in the habit of using standard Java naming conventions!

  5. #25
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

    Default Re: nullpointer but text is present

    After a lot of fuzz and re-coding things, I finally got to the centre of the problem:
    Why would one add a radio button to a combo box!

    Sure the combo box does not object to the button sitting on her.
    You see when adding the button to a menu or to a toolbar the button
    will keep its function and act still like a button (you'll click on it and it would scream)

    This stuff is, four you guys, as clear as parsing integers into carets, right!
    But for me the misunderstanding started when working with actions.
    When you add an action to a menu or toolbar is like adding a button.
    So I thought by adding a button to a combo box you add also its action (when it has one)
    and by clicking on the combo item the present radio button will give that action:
    ALL VERY WRONG!

    That is, of course, why I got the action string of a button when clicking on the combo.
    And that is why I could not do anything with that string!

    So I simply added a string array with the font names, added a inner-class-listener and
    directed the result to my (mvc-modeled) object that holds all results.

    It is indeed true when "over-wiring" the program with listeners and call-backs on looses
    control very easy, so I try to keep is simple.

    I used that same mvc-object also to trigger the actions for setting selections of all
    buttons/ combos and menus and I used the action objects to store the references of
    all the objects (I hope that is a good idea)

    I added the next code to surfman's small font-menu application (thanks)
    so the fonts appear in its family types and they scroll as well:

    Java Code:
    Font font;
            int count = 0;
            String[] availableFontFamilyNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
            for (String availableFontFamilyName : availableFontFamilyNames) {
                font = new Font(availableFontFamilyNames[count], Font.PLAIN, 16);
                JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(availableFontFamilyName);
                menuItem.addActionListener(listener);
                menuItem.setFont(font);
                fonts.add(menuItem);
                count++;
            }
    
            MenuScroller.setScrollerFor(fonts);
    
            bar.add(fonts);
    
            return bar;

    The next class does the scrolling (not from me, but I added the mouse wheel to it)

    Java Code:
    package willemwriter;
    
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import javax.swing.Icon;
    import javax.swing.JComponent;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JPopupMenu;
    import javax.swing.MenuSelectionManager;
    import javax.swing.Timer;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    import javax.swing.event.PopupMenuEvent;
    import javax.swing.event.PopupMenuListener;
    
    /**
     * A class that provides scrolling capabilities to a long menu dropdown or
     * popup menu.  A number of items can optionally be frozen at the top and/or
     * bottom of the menu.
     * <P>
     * <B>Implementation note:</B>  The default number of items to display
     * at a time is 15, and the default scrolling interval is 125 milliseconds.
     * <P>
     *
     * @version 1.5.0 04/05/12
     * @author Darryl
     */
    public class MenuScroller {
    
      //private JMenu menu;
      private JPopupMenu menu;
      private Component[] menuItems;
      private MenuScrollItem upItem;
      private MenuScrollItem downItem;
      private final MenuScrollListener menuListener = new MenuScrollListener();
      private int scrollCount;
      private int interval;
      private int topFixedCount;
      private int bottomFixedCount;
      private int firstIndex = 0;
      private int keepVisibleIndex = -1;
    
      /**
       * Registers a menu to be scrolled with the default number of items to
       * display at a time and the default scrolling interval.
       *
       * @param menu the menu
       * @return the MenuScroller
       */
      public static MenuScroller setScrollerFor(JMenu menu) {
        return new MenuScroller(menu);
      }
    
      /**
       * Registers a popup menu to be scrolled with the default number of items to
       * display at a time and the default scrolling interval.
       *
       * @param menu the popup menu
       * @return the MenuScroller
       */
      public static MenuScroller setScrollerFor(JPopupMenu menu) {
        return new MenuScroller(menu);
      }
    
      /**
       * Registers a menu to be scrolled with the default number of items to
       * display at a time and the specified scrolling interval.
       *
       * @param menu the menu
       * @param scrollCount the number of items to display at a time
       * @return the MenuScroller
       * @throws IllegalArgumentException if scrollCount is 0 or negative
       */
      public static MenuScroller setScrollerFor(JMenu menu, int scrollCount) {
        return new MenuScroller(menu, scrollCount);
      }
    
      /**
       * Registers a popup menu to be scrolled with the default number of items to
       * display at a time and the specified scrolling interval.
       *
       * @param menu the popup menu
       * @param scrollCount the number of items to display at a time
       * @return the MenuScroller
       * @throws IllegalArgumentException if scrollCount is 0 or negative
       */
      public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount) {
        return new MenuScroller(menu, scrollCount);
      }
    
      /**
       * Registers a menu to be scrolled, with the specified number of items to
       * display at a time and the specified scrolling interval.
       *
       * @param menu the menu
       * @param scrollCount the number of items to be displayed at a time
       * @param interval the scroll interval, in milliseconds
       * @return the MenuScroller
       * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
       */
      public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval) {
        return new MenuScroller(menu, scrollCount, interval);
      }
    
      /**
       * Registers a popup menu to be scrolled, with the specified number of items to
       * display at a time and the specified scrolling interval.
       *
       * @param menu the popup menu
       * @param scrollCount the number of items to be displayed at a time
       * @param interval the scroll interval, in milliseconds
       * @return the MenuScroller
       * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
       */
      public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval) {
        return new MenuScroller(menu, scrollCount, interval);
      }
    
      /**
       * Registers a menu to be scrolled, with the specified number of items
       * to display in the scrolling region, the specified scrolling interval,
       * and the specified numbers of items fixed at the top and bottom of the
       * menu.
       *
       * @param menu the menu
       * @param scrollCount the number of items to display in the scrolling portion
       * @param interval the scroll interval, in milliseconds
       * @param topFixedCount the number of items to fix at the top.  May be 0.
       * @param bottomFixedCount the number of items to fix at the bottom. May be 0
       * @throws IllegalArgumentException if scrollCount or interval is 0 or
       * negative or if topFixedCount or bottomFixedCount is negative
       * @return the MenuScroller
       */
      public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval,
              int topFixedCount, int bottomFixedCount) {
        return new MenuScroller(menu, scrollCount, interval,
                topFixedCount, bottomFixedCount);
      }
    
      /**
       * Registers a popup menu to be scrolled, with the specified number of items
       * to display in the scrolling region, the specified scrolling interval,
       * and the specified numbers of items fixed at the top and bottom of the
       * popup menu.
       *
       * @param menu the popup menu
       * @param scrollCount the number of items to display in the scrolling portion
       * @param interval the scroll interval, in milliseconds
       * @param topFixedCount the number of items to fix at the top.  May be 0
       * @param bottomFixedCount the number of items to fix at the bottom.  May be 0
       * @throws IllegalArgumentException if scrollCount or interval is 0 or
       * negative or if topFixedCount or bottomFixedCount is negative
       * @return the MenuScroller
       */
      public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval,
              int topFixedCount, int bottomFixedCount) {
        return new MenuScroller(menu, scrollCount, interval,
                topFixedCount, bottomFixedCount);
      }
    
      /**
       * Constructs a <code>MenuScroller</code> that scrolls a menu with the
       * default number of items to display at a time, and default scrolling
       * interval.
       *
       * @param menu the menu
       */
      public MenuScroller(JMenu menu) {
        this(menu, 15);
      }
    
      /**
       * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
       * default number of items to display at a time, and default scrolling
       * interval.
       *
       * @param menu the popup menu
       */
      public MenuScroller(JPopupMenu menu) {
        this(menu, 15);
      }
    
      /**
       * Constructs a <code>MenuScroller</code> that scrolls a menu with the
       * specified number of items to display at a time, and default scrolling
       * interval.
       *
       * @param menu the menu
       * @param scrollCount the number of items to display at a time
       * @throws IllegalArgumentException if scrollCount is 0 or negative
       */
      public MenuScroller(JMenu menu, int scrollCount) {
        this(menu, scrollCount, 150);
      }
    
      /**
       * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
       * specified number of items to display at a time, and default scrolling
       * interval.
       *
       * @param menu the popup menu
       * @param scrollCount the number of items to display at a time
       * @throws IllegalArgumentException if scrollCount is 0 or negative
       */
      public MenuScroller(JPopupMenu menu, int scrollCount) {
        this(menu, scrollCount, 150);
      }
    
      /**
       * Constructs a <code>MenuScroller</code> that scrolls a menu with the
       * specified number of items to display at a time, and specified scrolling
       * interval.
       *
       * @param menu the menu
       * @param scrollCount the number of items to display at a time
       * @param interval the scroll interval, in milliseconds
       * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
       */
      public MenuScroller(JMenu menu, int scrollCount, int interval) {
        this(menu, scrollCount, interval, 0, 0);
      }
    
      /**
       * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
       * specified number of items to display at a time, and specified scrolling
       * interval.
       *
       * @param menu the popup menu
       * @param scrollCount the number of items to display at a time
       * @param interval the scroll interval, in milliseconds
       * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
       */
      public MenuScroller(JPopupMenu menu, int scrollCount, int interval) {
        this(menu, scrollCount, interval, 0, 0);
      }
    
      /**
       * Constructs a <code>MenuScroller</code> that scrolls a menu with the
       * specified number of items to display in the scrolling region, the
       * specified scrolling interval, and the specified numbers of items fixed at
       * the top and bottom of the menu.
       *
       * @param menu the menu
       * @param scrollCount the number of items to display in the scrolling portion
       * @param interval the scroll interval, in milliseconds
       * @param topFixedCount the number of items to fix at the top.  May be 0
       * @param bottomFixedCount the number of items to fix at the bottom.  May be 0
       * @throws IllegalArgumentException if scrollCount or interval is 0 or
       * negative or if topFixedCount or bottomFixedCount is negative
       */
      public MenuScroller(JMenu menu, int scrollCount, int interval,
              int topFixedCount, int bottomFixedCount) {
        this(menu.getPopupMenu(), scrollCount, interval, topFixedCount, bottomFixedCount);
      }
    
      /**
       * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
       * specified number of items to display in the scrolling region, the
       * specified scrolling interval, and the specified numbers of items fixed at
       * the top and bottom of the popup menu.
       *
       * @param menu the popup menu
       * @param scrollCount the number of items to display in the scrolling portion
       * @param interval the scroll interval, in milliseconds
       * @param topFixedCount the number of items to fix at the top.  May be 0
       * @param bottomFixedCount the number of items to fix at the bottom.  May be 0
       * @throws IllegalArgumentException if scrollCount or interval is 0 or
       * negative or if topFixedCount or bottomFixedCount is negative
       */
      public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
              int topFixedCount, int bottomFixedCount) {
        if (scrollCount <= 0 || interval <= 0) {
          throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
        }
        if (topFixedCount < 0 || bottomFixedCount < 0) {
          throw new IllegalArgumentException("topFixedCount and bottomFixedCount cannot be negative");
        }
    
        upItem = new MenuScrollItem(MenuIcon.UP, -1);
        downItem = new MenuScrollItem(MenuIcon.DOWN, +1);
        setScrollCount(scrollCount);
        setInterval(interval);
        setTopFixedCount(topFixedCount);
        setBottomFixedCount(bottomFixedCount);
    
        this.menu = menu;
        menu.addPopupMenuListener(menuListener);
        menu.addMouseWheelListener(new MouseScrollListener());
      }
    
      /**
       * Returns the scroll interval in milliseconds
       *
       * @return the scroll interval in milliseconds
       */
      public int getInterval() {
        return interval;
      }
    
      /**
       * Sets the scroll interval in milliseconds
       *
       * @param interval the scroll interval in milliseconds
       * @throws IllegalArgumentException if interval is 0 or negative
       */
      public void setInterval(int interval) {
        if (interval <= 0) {
          throw new IllegalArgumentException("interval must be greater than 0");
        }
        upItem.setInterval(interval);
        downItem.setInterval(interval);
        this.interval = interval;
      }
    
      /**
       * Returns the number of items in the scrolling portion of the menu.
       *
       * @return the number of items to display at a time
       */
      public int getscrollCount() {
        return scrollCount;
      }
    
      /**
       * Sets the number of items in the scrolling portion of the menu.
       *
       * @param scrollCount the number of items to display at a time
       * @throws IllegalArgumentException if scrollCount is 0 or negative
       */
      public void setScrollCount(int scrollCount) {
        if (scrollCount <= 0) {
          throw new IllegalArgumentException("scrollCount must be greater than 0");
        }
        this.scrollCount = scrollCount;
        MenuSelectionManager.defaultManager().clearSelectedPath();
      }
    
      /**
       * Returns the number of items fixed at the top of the menu or popup menu.
       *
       * @return the number of items
       */
      public int getTopFixedCount() {
        return topFixedCount;
      }
    
      /**
       * Sets the number of items to fix at the top of the menu or popup menu.
       *
       * @param topFixedCount the number of items
       */
      public void setTopFixedCount(int topFixedCount) {
        if (firstIndex <= topFixedCount) {
          firstIndex = topFixedCount;
        } else {
          firstIndex += (topFixedCount - this.topFixedCount);
        }
        this.topFixedCount = topFixedCount;
      }
    
      /**
       * Returns the number of items fixed at the bottom of the menu or popup menu.
       *
       * @return the number of items
       */
      public int getBottomFixedCount() {
        return bottomFixedCount;
      }
    
      /**
       * Sets the number of items to fix at the bottom of the menu or popup menu.
       *
       * @param bottomFixedCount the number of items
       */
      public void setBottomFixedCount(int bottomFixedCount) {
        this.bottomFixedCount = bottomFixedCount;
      }
    
      /**
       * Scrolls the specified item into view each time the menu is opened.  Call this method with
       * <code>null</code> to restore the default behavior, which is to show the menu as it last
       * appeared.
       *
       * @param item the item to keep visible
       * @see #keepVisible(int)
       */
      public void keepVisible(JMenuItem item) {
        if (item == null) {
          keepVisibleIndex = -1;
        } else {
          int index = menu.getComponentIndex(item);
          keepVisibleIndex = index;
        }
      }
    
      /**
       * Scrolls the item at the specified index into view each time the menu is opened.  Call this
       * method with <code>-1</code> to restore the default behavior, which is to show the menu as
       * it last appeared.
       *
       * @param index the index of the item to keep visible
       * @see #keepVisible(javax.swing.JMenuItem)
       */
      public void keepVisible(int index) {
        keepVisibleIndex = index;
      }
    
      /**
       * Removes this MenuScroller from the associated menu and restores the
       * default behavior of the menu.
       */
      public void dispose() {
        if (menu != null) {
          menu.removePopupMenuListener(menuListener);
          menu = null;
        }
      }
    
      /**
       * Ensures that the <code>dispose</code> method of this MenuScroller is
       * called when there are no more refrences to it.
       *
       * @exception  Throwable if an error occurs.
       * @see MenuScroller#dispose()
       */
      @Override
      public void finalize() throws Throwable {
        dispose();
      }
      
    
      private void refreshMenu() {
        if (menuItems != null && menuItems.length > 0) {
          firstIndex = Math.max(topFixedCount, firstIndex);
          firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);
    
          upItem.setEnabled(firstIndex > topFixedCount);
          downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);
    
          menu.removeAll();
          for (int i = 0; i < topFixedCount; i++) {
            menu.add(menuItems[i]);
          }
          if (topFixedCount > 0) {
            menu.addSeparator();
          }
    
          menu.add(upItem);
          for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
            menu.add(menuItems[i]);
          }
          menu.add(downItem);
    
          if (bottomFixedCount > 0) {
            menu.addSeparator();
          }
          for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
            menu.add(menuItems[i]);
          }
    
          JComponent parent = (JComponent) upItem.getParent();
    
          int preferredWidth = 0;
          for (Component item : menuItems) {
            preferredWidth = Math.max(preferredWidth, item.getPreferredSize().width);
          }
          menu.setPreferredSize(new Dimension(preferredWidth, menu.getPreferredSize().height));
    
          parent.revalidate();
          parent.repaint();
        }
    
      }
    
      private class MenuScrollListener implements PopupMenuListener {
    
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
          setMenuItems();
        }
    
        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
          restoreMenuItems();
        }
    
        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
          restoreMenuItems();
        }
    
        
    
        private void setMenuItems() {
          menuItems = menu.getComponents();
          if (keepVisibleIndex >= topFixedCount
                  && keepVisibleIndex <= menuItems.length - bottomFixedCount
                  && (keepVisibleIndex > firstIndex + scrollCount
                  || keepVisibleIndex < firstIndex)) {
            firstIndex = Math.min(firstIndex, keepVisibleIndex);
            firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1);
          }
          if (menuItems.length > topFixedCount + scrollCount + bottomFixedCount) {
            refreshMenu();
          }
        }
         
    
        private void restoreMenuItems() {
          menu.removeAll();
          for (Component component : menuItems) {
            menu.add(component);
          }
        }
      }
    
      private class MenuScrollTimer extends Timer {
    
        public MenuScrollTimer(final int increment, int interval) {
          super(interval, new ActionListener() {
    
            @Override
            public void actionPerformed(ActionEvent e) {
              firstIndex += increment;
              refreshMenu();
            }
          });
        }
    
        
       
      }
    
      private class MenuScrollItem extends JMenuItem
              implements ChangeListener {
    
        private MenuScrollTimer timer;
    
        public MenuScrollItem(MenuIcon icon, int increment) {
          setIcon(icon);
          setDisabledIcon(icon);
          timer = new MenuScrollTimer(increment, interval);
          addChangeListener(this);
        }
    
        public void setInterval(int interval) {
          timer.setDelay(interval);
        }
    
        @Override
        public void stateChanged(ChangeEvent e) {
          if (isArmed() && !timer.isRunning()) {
            timer.start();
          }
          if (!isArmed() && timer.isRunning()) {
            timer.stop();
          }
        }
        
      }
      
    
      private static enum MenuIcon implements Icon {
    
        UP(9, 1, 9),
        DOWN(1, 9, 1);
        final int[] xPoints = {1, 5, 9};
        final int[] yPoints;
    
        MenuIcon(int... yPoints) {
          this.yPoints = yPoints;
        }
    
        @Override
        public void paintIcon(Component c, Graphics g, int x, int y) {
          Dimension size = c.getSize();
          Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
          g2.setColor(Color.GRAY);
          g2.drawPolygon(xPoints, yPoints, 3);
          if (c.isEnabled()) {
            g2.setColor(Color.BLACK);
            g2.fillPolygon(xPoints, yPoints, 3);
          }
          g2.dispose();
        }
    
        @Override
        public int getIconWidth() {
          return 0;
        }
    
        @Override
        public int getIconHeight() {
          return 10;
        }
      }
        private class MouseScrollListener implements MouseWheelListener {
            public void mouseWheelMoved(MouseWheelEvent mwe){
                firstIndex += mwe.getWheelRotation();
                refreshMenu();
                mwe.consume(); // (Comment 16, Huw)
            }
        }
    }
    Last edited by willemjav; 02-08-2014 at 09:39 PM.

  6. #26
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,008
    Rep Power
    3

    Default Re: nullpointer but text is present

    You can leave the "count" variable out. You already have the fontname:
    Java Code:
    font = new Font(availableFontFamilyName, Font.PLAIN, 16);
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  7. #27
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,075
    Rep Power
    8

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Reading a zip/text file present in a MAC Bundle
    By Prasannaa in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2008, 04:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •