Adding JScrollPane to a JList problems

Hi,
I am having problem in trying to add a JScrollPane to a JList, it doesnt appear i don't understand what i am doing wrong.
private String [] mainMenu = {"Phonebook", "Messages", "User Options", "Phone Status"};
private JList main = new JList(mainMenu);
private JScrollPane scrolling = new JScrollPane(main);
public Mobile()
         main.setLocation(60, 110);
         main.setSize(90, 50);
         add(scrolling);
         scrolling.setVisible(true);
}

The code to run the app is:
import java.awt.*;
import javax.swing.*;
class MobileGUI {
     public static void main(String[] args) {
          JFrame frame = new JFrame("Mobile Phone Simulation");
          Container pane = frame.getContentPane();
          pane.add(new Mobile());
          frame.setSize(340, 625);
          frame.show();
}The class that contains the components is:
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.*;
import java.io.*;
import java.lang.*;
class Mobile extends JComponent {
private String[] mainMenu = {"Phonebook", "Messages", "User Options", "Phone Status"};
private JList main = new JList(mainMenu);
private JScrollPane scrolling = new JScrollPane(main);
public JTextArea display = new JTextArea(6, 30);
public MobileGUI()
          //Displays
          setLayout(null);
          //Display for messages
          display.setLocation(120, 60);
          display.setSize(90, 50);
          add(display);
          display.setVisible(false);
          //MainMenu Jlist Display
          main.setLocation(120, 60);
          main.setSize(90, 50);
          add(scrolling);
          scrolling.setVisible(true);
     public void paint(Graphics g) {
     g.setColor(Color.gray.brighter());
     g.fillRoundRect(30, 30, 270, 530, 40, 20);
     g.setColor(Color.black);
     g.fillArc(30, 30, 270, 320, 0, 180);
    g.fillArc(30, -180, 270, 740, 180, 180);
     g.setColor(Color.gray);     
     super.paint(g);       
}The JList does not appear neither does the JScrollPane

Similar Messages

  • Java Turduckin: JScrollPane in a JList in a JScrollPane

    Probably a quick answer for someone: I have a JScrollPane containing a JList. The JList has a custom renderer that returns a subclass of JScrollPane: the idea is a scrollable list of individual panels of scrollable text.
    Is this possible? When I run it, it looks ok (the inner scroll bar hilights correctly, etc), but, even after a fair amount of investigation, I can't get the inner scrollbar to respond to the mouse. Can I get JList to forward clicks?
    Many thanks,
    -bmeike

    Renderers return a picture, not something you can interact with.
    Try setting your inner JScrollPane as the editor.

  • Adding JScrollPane on JPanel??Is there any problem.??

    hi,
    I have a JPanel over which i added a JScrollPane on to whose view portvie i added a JTable.
    But the problem is the table is not getting visble.Not only table all the components i add to scrollpane which on a panel is not getting displayed.
    Am i missing something??
    final JScrollPane scrollPane = new JScrollPane();
              panel.add(scrollPane);
              table = new JTable();
              scrollPane.setViewportView(table);

    Make sure to add the panel to the content pane as well.
    If the problem still persists, then please post a simple executable demo program that demonstrates the behavior.

  • Adding JScrollPane to CardLayout

    public static void panelLayout (String panel)
            cardPanel.add (Rosters.rosterPanel1, "roster1");
            cardPanel.add (Rosters.rosterPanel2, "roster2");
            cardPanel.add (OP300.evalLoadPane1, "op300load1"); // JScrollPane with JPanel inside
            cardPanel.add (mainPanel, "main");
            CardLayout showPanel = (CardLayout)(cardPanel.getLayout ());
            showPanel.show (cardPanel, panel);
        }I'm trying to add a JScrollPane to my CardLayout just like I have with the other JPanels. All of the other JPanels work fine, but adding the JScrollPane is giving me issues. As soon as PanelLayout() is called, even if it isn't calling for the JScrollPane, I'm getting: Exception occurred during event dispatching:
    java.lang.NullPointerException
            at java.awt.Container.addImpl(Container.java:1027)
            at java.awt.Container.add(Container.java:903)
            at HubEvals.panelLayout(HubEvals.java:540)
            at Login.b_loginActionPerformed(Login.java:175)
            at Login.access$000(Login.java:18)
            at Login$1.actionPerformed(Login.java:92)
            ...The JScrollPane modifier is public static so it isn't having problems getting access to it. I even tried putting the JScrollPane inside a JPanel so it would be like:
    - JPanel
    ----- JScrollPane
    ---------- JPanel (panel that is longer than the frame itself, hence why it's in a scroll pane)
    I still got the same error.

    This time I remembered to initialize it. I added it to my initComponents() method and I was still getting the problem:public HubEvals ()
            initComponents ();
            new Rosters ();
            new OP300 ();
            RegisterLogin intro = new RegisterLogin ();
            intro.showInDialog (this);
        }I had accidentally typed new OP3O0 (); instead of new OP300 ();. What's up with that? The first thing I typed doesn't even exist as a method, class, or variable and it still passed NetBeans validation. I spent well over 50 minutes on a stupid '0' being an 'O' and the 2 characters look exactly the same in the code font.
    Anyway, thanks. Problem solved. Heh. You run into stuff like this when you don't leave the computer for hours at a time.

  • Help ! using Calendar & adding text to a page problem !!

    Let's hope I make this clear enough for someone to understand.
    I am making up a Calendar & I want to add text to certain pages ( photo ).
    I click on 'Design' & pick option 2 ( the one where you can add text ), now here is my problem. The text box always starts the text from the right, when I have added the text I want to move it over to the Left or make it central but nothing happens when i hit the space bar, it stays on the right.
    Does anyone know a way so I can either move the text over to the Left or do something else to get it on the left or where ever I want it ?
    This is most frustrating. If I hit the 'spacebar' now I end up here.
    So why can't do it in Calendar !! OR am I just thick & missing something.
    Steve ( hope I made myself clear )

    Steve:
    What theme are you using? In my Pictures calendar the text box below the photos start at the left, i.e. left justified.
    But here's a possible way to get it where you want:
    1 - type in the text as you want, setting the size and font for the calendar.
    2 - copy the text out of the text box
    3 - open a text editor and past the text into it.
    4 - in the text editors formatting section select "left justification".
    5 - select all of the text in the text editor
    6 - do a select all in the calendar text box and past the text from the text editor. That should change the justification to whatever you want, left or center.
    Do you Twango?

  • JTable in JScrollPane auto resize refresh problem

    Hello,
    I have a JTable in a JScrollPane. Number of rows is changing.
    I'm using the following to auto-resize JScrollPane.
    public Dimension getPreferredSize() {
                  Dimension size = super.getPreferredSize();
                  size.height -= getViewport().getPreferredSize().height;
                  Component view = getViewport().getView();
                  if(view != null)
                  size.height += view.getPreferredSize().height;
                  return size;
             }There is a JButton, which adds an empty row to the JTable. It all works fine, except the auto-resize when a new row is added. I want all rows of JTable to be visible, with no scrollbars present. I tried repaint(), revalidate(), addNotify(). What should I do?
    Thanks.

    Sure
    DefaultTableModel dtm = new DefaultTableModel(vec, header);
              jt0 = new JTable(dtm);
              jt0.getTableHeader().setReorderingAllowed(false);
              jt0.setFont(new Font("Tahoma", Font.PLAIN, 12));
              jt0.getTableHeader().setFont(new java.awt.Font("Tahoma", java.awt.Font.BOLD, 12));
              jt0.setRowHeight(18);
            jt0.setPreferredScrollableViewportSize(new Dimension(500, jt0.getRowCount() * jt0.getRowHeight()));
            jt0.setFillsViewportHeight(false);
              jsp0 = new JScrollPane(jt0);
    GridBagConstraints gbc = new GridBagConstraints(); 
            gbc.insets = new Insets(2,1,2,1); 
            gbc.weightx = 1.0; 
            gbc.weighty = 1.0; 
            JPanel p0 = new JPanel(new GridBagLayout()); 
            gbc.fill = gbc.HORIZONTAL;
            p0.add(jsp0, gbc);
              JButton jb1 = new JButton("add row");
              jb1.setSize(40, 18);
    jb1.addActionListener(new java.awt.event.ActionListener() {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        dtm.addRow(new Object[]{....});
    //                    jt0.scrollRectToVisible(jt0.getCellRect(jt0.getModel().getRowCount()-1, 1, false));
    //                    jt0.setRowSelectionInterval(jt0.getModel().getRowCount()-1, jt0.getModel().getRowCount()-1);
        public class SizeX extends JScrollPane {
             public Dimension getPreferredSize() {
                  Dimension size = super.getPreferredSize();
                  size.height -= getViewport().getPreferredSize().height;
                  Component view = getViewport().getView();
                  if(view != null)
                  size.height += view.getPreferredSize().height;
                  return size;
        }

  • Problem Adding Audio to iMovie (Filevault Problem?)

    Ok... I made an iMovie project when I returned from a trip.  I then turned on Filevault in Lion for full disk encryption (I've been waiting for this feature because I need it for my business).  I went back to make some edits in my video... and iMovie is now behaving differently.  When I add a song from iTunes, it won't play... not even a peep.  I can move and adjust the songs currently in the video but any new tracks get silence.
    I can play the songs in iTunes and even in the lower pane of iMovie... just not in the video itself.  Is this a problem with iMovie or is Filevault causing this?  Anyone know how to overcome this?

    Update... I turned off Filevault.  No change.  Added iTunes tracks still don't play.

  • JList problem "again??"

    hi i dont mean to double post but i dont think i pasted in enought code before when i posted this problem, so here is some more if anyone can
    help me out i send them 5 more of the little guys
    thanks againhello
    privious post!!
    "i want to get the selected value/values from a Jlist and put them into a SQL query i think i should have each selected value as a string so i can concatinate them into the query but i cant seem to be able to do this does any one know how can acheive this??"
    code:
    JInternalFrame frame3 = new JInternalFrame("User Adminstration info",true,true,true,true);
    Container content = frame3.getContentPane();
    JLabel l1=new JLabel("Username");
    JLabel l2=new JLabel("Hostname");
    JLabel l3=new JLabel("Password");
    JTextField t1=new JTextField(11);
    JTextField t2=new JTextField(11);
    JPasswordField pass1=new JPasswordField(11);
    JPanel p1=new JPanel();
    String all = "ALL Privileges";
    JList privilegesList;
    String privilegetype[]={"SELECT","INSERT","UPDATE","DELETE","CREATE","DROP"};
    JList databaseList;
    String databasename[] = {"db1","db2","db4","db5",};
         JPanel p2=new JPanel();
         JPanel p3=new JPanel();
    JButton b1=new JButton("Submit Details");
         JPanel p4=new JPanel();
         JPanel p5=new JPanel();
         JPanel p6=new JPanel();
    frame3.setVisible(true);
         content= frame3.getContentPane();
         content.setLayout(new BorderLayout());
         p1.setLayout(new GridLayout(3,2));
         privilegesList = new JList( privilegetype );
                                  privilegesList.setVisibleRowCount( 5 );
                                  privilegesList.setFixedCellHeight( 15 );
                                  privilegesList.setFixedCellWidth( 150 );
                                  privilegesList.setSelectionMode(
                                  ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
         databaseList = new JList( databasename);
                                  databaseList.setVisibleRowCount( 5 );
                                  databaseList.setFixedCellHeight( 15 );
                                  databaseList.setFixedCellWidth( 150 );
                                  databaseList.setSelectionMode(
                                  ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
    p1.add(l1);p1.add(t1);
    p1.add(l2);p1.add(t2);
    p1.add(l3);p1.add(pass1);
    p1.setBorder(new TitledBorder(new EtchedBorder(),"User Details "));
    //p2.setLayout(new GridLayout(8,0));
         p2.add(privilegesList);
         p2.setBorder(new TitledBorder(new EtchedBorder(),"Privileges"));
         //p3.setLayout(new GridLayout(5,0));
         p3.add(databaseList);
         p3.setBorder(new TitledBorder(new EtchedBorder(),"DataBases"));
         p4.setLayout(new GridLayout(0,2));
         p4.add(p2);
    p4.add(p3);
         p6.add(b1);
         content.add(p1,BorderLayout.NORTH);
         content.add(p4,BorderLayout.CENTER);
                             content.add(p6,BorderLayout.SOUTH);
                   p5.setBorder(new TitledBorder(new EtchedBorder(),"User Adimnstration"));
                   frame3.setSize(500,430);
                   thedesktop.add( frame3);
                   setVisible(true);

    I suggest you read this section from the Swing tutorial on "How to Use Lists" for sample code and explanations:
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

  • JList problems, can't write to a list

    Hi there....can anyone help???
    I'm having a problem with a dialog box...I use a dialog box to logon a new user (client) to my server, but the GUI on the client's side isn't showing who's online so to speak(I'm using a JList as my 'buddy' list type of window)....How do I get the dialog box to send the user's name to my client's GUI and add it to my who's online box??? Conversely how do I get the name to be removed when the user disconnects from the server??? Thanks everyone for any help you can provide....

    You need to refresh the JList every time the data changes:
    JList myjlist = new JList();
    Vector data = new Vector(); //or use an array of type Object
    //data changes
    myjlist.setListData(data);

  • Adding Scroll Bar in Jlist

    Hello
    Could anybody suggest me how can I add scroll bar in Jlist. I tried this one, but it did not work
    JList list = new JList(subject);
    JScrollPane scrollPane = new JScrollPane(list);
    Thanks
    Prashanth

    Posting another question without replying to the responses on your previous thread, are you? Good luck getting help with this one.
    db

  • Adding existing mail account - Technical problem

    A bit of background...
    I run my own mailserver (Exim 4) and wish to add my current email account to my blackberry service through T-Mobile in the UK ([email protected])
    In order to do this I have to use T-Mobile's webpage to add the account details, however thsi si what is causing me the headache. After adding all the details the webpage runs a script to connect to my server in order to establish a trust relationship (so I am told by T-Mobile tech support) The page produces an error saying "An error occurred during email account verification. Please check your information and try again"
    When checking the error logs on my server I see this:-
    2008-04-18 15:13:40 SMTP protocol violation: synchronization error (input sent without waiting for greeting): rejected connection from H=mail.bis.eu.blackberry.com [216.9.253.4] 
    Basically from what I can tell script that runs the verification check does not wait for the usual greetings for each line of input from the server.
    I have made the suggested changes to the exim.conf file (googled the error) but I am still having the same problem.
    What I need to know is if anyone knows a way to add this account without using my providers webpage?
    Regards
    Jerry 

    Have you tried to add from your BB. Just go to SetUp Email on the menu screen on your BB and Click add Email Account. It might work that way.
    BB Pearl 8100 T-Mobile
    http://ourfunctionalfamily.com

  • Adding JScrollPane to JInternalFrame

    Hello, I have been having a rather difficult time adding a a jscrollpane to my jinternalframe. I have a panel that I am adding some objects to. I add that panel to a jscrollpane, then add the jscrollpane to the container of the JInternalFrame. I get no errors, but when I run this thing, the panel spills out over the JInternalFrame, the panel is bigger than the internal frame. When I take the jscrollpane off of it and just add the panel directly to the JInternalFrame, it fits jsut fine. However, I need the scrollbar to view all of the material. Any ideas? Here is a piece of my code.
             JInternalFrame internal = new JInternalFrame("New Tree",true,true,true,true);
          Container c = internal.getContentPane();
    //this panel is something I created earlier and have added stuff to it
    //panel is of the type java.awt.panel
            panel.setBackground(Color.white);
            JScrollPane jsp = new JScrollPane();
            jsp.setViewportView(panel);
            c.add(jsp);
            internal.setSize(700,400);
            internal.setOpaque(true);
            internal.setVisible(true);
    //I add it to a desktop pane a little later on

    Here's an example:
    import java.awt.*;
    import javax.swing.*;
    public class InternalFrameTest extends JFrame {
         private JInternalFrame internalFrame1;
         private JInternalFrame internalFrame2;
         private JScrollPane scrollPane;
         private JDesktopPane desktopPane;
         public InternalFrameTest() {
              try {
                   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   desktopPane = new JDesktopPane();
                   scrollPane = new JScrollPane(desktopPane);
                   desktopPane.setPreferredSize(new Dimension(350, 250));
                   internalFrame1 = new JInternalFrame();
                   desktopPane.add(internalFrame1);
                   internalFrame1.setBounds(30, 30, 100, 100);
                   internalFrame1.setVisible(true);
                   internalFrame2 = new JInternalFrame();
                   desktopPane.add(internalFrame2);
                   internalFrame2.setBounds(150, 100, 100, 100);
                   internalFrame2.setVisible(true);
                   getContentPane().add(scrollPane, BorderLayout.CENTER);
                   pack();
                   setSize(300, 200);
                   setLocationRelativeTo(null);
                   setVisible(true);
              } catch (Exception e) { e.printStackTrace(); }
         public static void main(String[] args) { new InternalFrameTest(); }
    }

  • Adding a String into JList....Please guide

    How can I add a String to a JList component??
    JList jL = new JList("Abcd");
    does not work!!!
    I need to add a 'String' value to a JList and then
    say :
    c.add(new JScrollPane(jL)); // c is the container.
    Can someone please advise?

    hello,
    JList constructor takes Object[] and not single String.
    try: JList list = new JList(new Object[]{"yourString","yourSecondString"});regards
    tim

  • Jlist problems

    I am having problems with Jlist such that it returns index selectedIndex values in the valueChanged method from its interface method.
    SwingUtilities.invokeLater(
    new Runnable()
    public void run()
    coLogger.debug("csLocationName = " + csLocationName);
    csLocationName = SVOpSParseKanji.convertDelimToKanji(csLocationName) ;
    coLocationTxtFld.setText(csLocationName);
    coListModel.setValues(coWrapperFacilityList);
    coList.clearSelection();
    populateGeneralFacilityTypeList(coFacilityTypeLists);
    if(coTempFacility.getFcltDataInfo().getFcltCode().length() > 0)
    int iIndex = coListModel.getIndexed(coFacility);
    coList.setSelectedIndex(iIndex);
    coList.ensureIndexIsVisible(iIndex);
    coGlassPane.setVisible(false);
    after setting this the valueChanged method returns
    a selectedIndex value of 5 and 10
    what seems to be the problem?.. thanks

    a selectedIndex value of 5 and 10if the problem is you are getting 2 values, itemStateChanged() fires twice,
    once for DESELECTED, again for SELECTED
    you separate the two by checking getStateChange()

  • Adding To The LIst Of Problems With Internet Explolrer 11 And Another Browser

    I've b1 of the EA6500 router and like the othe posts I can't use IE 11.  The "solution" is to use either Chrome or Firefox but not my Chrome has stopped working.  All I get now is the LInksys Blue background.  When I first see the site it looks like it's trying but then gives me a blue page.  I've included screen prints of what I see when I go to Linksys Smart Wi-Fi page and below that is the version number.  I have deleted my browser history, cache, saved form data, etc. but the result is still the same.  And it doesn't matter if I use the router IP address or the Smartsys Wi-Fi link.
    So right now the only broweser that will let me do router administration is Firefox but something tells me it too will have problems eventually.
    the problem I'm having isn't with the router, it is with the company.  People have tried to blame Micrtosoft in these posts for the problem but it's not their problem.  The real kicker is that these Smart Wi-Fi routers are not old. nor are they cheap.  LInksys announced this line at CES 2012, then again in April, and the last one announced for thie "initial" line-up of new routers  was the EA6500 (the EA6500 was anounced in June 2012).
    I've been mostly happy with LInksys reouters but if this is the way they are going to conduct business, then maybe I need to make certain adjustments with the networking products we purchase. 
    To put it bluntly...this situation is unacceptable.

    Believe it or not I stumbled across the solution to the problem and need to partially retract one of my previous statements.  In a sense part of the responsibility does go to Microsoft because during one of their infamous "updates", the default version of Internet Explorer was changed to use the 64-bit version.  I rarely used the Internet Explorer (64 bit) link in my Start Menu...I always used the "default" which apparently was the 32-bit version because there are plenty of companies that have not updated their software for 64-bit.
    The article I came across is Problem With Internet Explorer? Maybe You Need Fewer Bits.  The fix is simple and all it really takes is to right-click the icon for Internet Explorer and choose "Properties".  When that comes up change the value in the "Target" field from "C:\Program Files\Internet Explorer\iexplore.exe" to "C:\Program Files (x86)\Internet Explorer\iexplore.exe".  Once you make the change save the change and then use that link to get to administer your browser.  I tried it and it worked.  I guess I missed the post from Linksys Support about that possibility.

Maybe you are looking for