String in JList

I've a string like this: "aaaa bb cccccc dddd eeeee", I want to put in a JList separately (1) aaaa; 2)bb ecc..).
Can somebody help me with a little piece of code?
Tnx!

1) Read the StringTokenizer API to learn how to split the long string into separate Strings.
2) Read the Swing tutorial on "How to Use Lists" to learn how to add the Strings to the JList
http://java.sun.com/docs/books/tutorial/uiswing/components/list.html

Similar Messages

  • How to do the multiple-line String at JList? help!

    i need some code to multiple-line String at JList.
    i know that it is can be done by html code.
    example:
    <p>line1</p><p>line2</p>
    but if i use that html code...
    i face another problem to my JList..
    it cannot set the font use the ListCellRenderer..
    like:
    public Component getListCellRendererComponent(
    JList list,
    Object value,
    int index,
    boolean isSelected,
    boolean cellHasFocus)
    Color newColor = new Color(230, 230, 230);
    setIcon(((DisplayItem)value).getIcon());
    setText(((DisplayItem)value).getChat());
    setFont(((DisplayItem)value).getFont());
    setBackground(isSelected ? newColor : Color.white);
    setForeground(isSelected ? Color.black : Color.black);
    if (isSelected) {
    setBorder(
    BorderFactory.createLineBorder(
    Color.red, 2));
    } else {
    setBorder(
    BorderFactory.createLineBorder(
    list.getBackground(), 2));
    return this;
    all my JList will be html type...
    i don't want that happen..can be another method to do that multiple-line String in JList??
    i also need to set a icon image between string in the JList. anyone get idea??
    i need ur help!
    thank you.

    I think you should create/override several methods like setText(String), setIcons(Icon[]), paintComponent(Graphics), getMinimumSize(), getPreferredSize(), etc.
    I would like to code like below...:class MultilineLabel extends JLabel {
        private String[] text = null;
        private ImageIcon[] icons = null;
        public void setText( String newText ) {
            // It overrides JLabel.setText( String )
            // Tokenize newText with line-separator
            // and put each text into the 'text' array.
        public void setIcons( Icon[] newIcon ) {
            // It is similar to JLabel.setIcon( Icon ) method,
            // but it receives an array of Icon-s. Set these icons to 'icons' variable.
        public void paintComponent( Graphics g ) {
            // It overrides JComponent.paintComponent( Graphics ) method.
            super.paintComponent( g );
            if ( text != null && icons != null ) {
                int icon_x = 0;
                int text_x = 0;
                int y = 0;
                // draw customized content..
                for ( int i=0; i<text.length; i++ ) {
                    // compute x and y locations
                    // icon_x = ...
                    // text_x = ...
                    // y = ...
                    // and draw it!
                    g.drawString( text[ i ], text_x, y );
                    icon[ i ].paintIcon( this, g, icon_x, y );
        public Dimension getMinimumSize() {
            int width = super.getMinimumSize().width;
            int height = ... // I think you must compute it with 'text' and 'icons'' arrays.
            return new Dimension( width, height );
        public Dimension getPreferredSize() {
            int width = super.getPreferredSize().width;
            int height = ...
            return new Dimension( width, height );
    }I think that code-structure above is the minimum to implement your requirements. (Of course if you want to implement it :)
    Good luck and let me know it works or not. :)

  • 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

  • How to do the multiple-line String at JList?

    hey everyone,
    i want to create a JList have to display multiple-line string.
    i have use String a="text1"+"\n"+"text2" inside my JList...
    the "\n" change to a sequare box...
    how cum like that.................??
    i need ur kindly helping...

    Because the default renderer for a JList element is a
    JLabel, and that is how JLabel behaves. The question
    "how to do a multiple-line JLabel" has been asked
    hundreds of times in this forum, search for that.i have search for it already but i no get it..anything!
    so, can u give me the url for me? thank you!

  • How can I add the string to JList

    I have one string " teletoppy" and I have Jlist which have 5 items in it.
    After I press submit I want teletoppy added to the list.
    How can I write the command?
    because I try by using command_list.add("teletoppy", comp);
    I don't know what component is?how can I add it in?.

    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/list.html]How to Use Lists for a working example of how to do this. The "Hire" button adds the text from the text field to the JList.

  • Selecting a string from Jlist

    Hi guys, I am trying to search a list for a string, then if there is no string in the list that matches my search,i want to add a new string to the list..
    here is my code, but tmp is not getting any value...
    int j = 0;
    String tn,tmp;
           while (result.next())
                             j++;
                             tn = result.getString("UserResponsible");
                             for(int f = 0;f<j;f++)
                                  uList.setSelectedIndex(f);
                                  String tmp = new String(uList.getSelectedValue().toString());
                                  if(tn.compareTo(tmp)== 0)
                                       uModel.addElement(tn);
                                       utwoModel.addElement(tn);     
                             x = uModel.getSize();          
                             y =utwoModel.getSize();
                        }     

    sorry i dont know what i pressed and i posted up three questions by accident

  • Regarding jList

    I want to create a list of members like buddies list in yahoo messenger?Give me some ideas.
    Is there any provision to add icons and string in JList?
    Narayanan.R
    Mail Id: [email protected]

    look at your other post
    http://forum.java.sun.com/thread.jsp?thread=217674&forum=57&message=756255

  • Image Caching With JList

    Hi all, I need to know, how can I implement an Image Cache feature with a JList that is effective, ie. basic I would like the images to be stored in memory when the list is visible (done that already using a WeakHashMap<String, Icon>) and removed from memory when the JList is not displayed.
    Currently I use the following code section, to try and remove the data from memory, seems not work according to task manager. Sorry I cannot seem to come up with a good SSCCE since I'm not exactly sure how to make an example that loads images. Any suggestion with that?
    WeakHashMap<String,Icon> icons = new WeakHashMap<String,Icon>();
    JList list = new JList(); // something like this in actual code
    public void startClearTimer() {
        new javax.swing.Timer( 30000, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if(!list.isShowing() && icons.size() > 0 ) {
                    resetIconCache();
                    System.out.println("Icons Cleared");
                    System.gc();
                    //((javax.swing.Timer)e.getSource()).stop();
        }).start();
    public void resetIconCache() {
        if(icons == null) {
            return;
        Iterator<Icon> images = icons.values().iterator();
        while(images.hasNext()) {
            ImageIcon icon = (ImageIcon)images.next();
            icon.getImage().flush(); // smoke but no cigar
            icon = null;
        icons.clear();
        icons = new WeakHashMap<String,Icon>();
    }This code is used in a ListCellRenderer, which loads the images, scales them, caches them in memory so the repaints are faster and displays them along side some JLabels.
    So basically how can I load the images in memory and release the resources used when the images are not required?
    ICE

    you can't be cleverer than JVM for memory usage.
    Of course you can, because the point of caching is that it requires (or at the very least is optimised by) some understanding of the use case. JVMs are somewhat unlikely to predict how any given set of users will use any given application, nor are they capable of factoring in the cost of downloading (or otherwise obtaining) data which has been freed from memory. To a JVM, a lump of voidable memory is no different to any other.
    Take an example of an applet (which is limited to 96Mb of heap) which browses images on a server. Let's say it's looking at images which occupy 20Mb of memory each (far from unreasonable) in memory. They might each be 1Mb or so in compressed file size, which is an appreciable delay in download time.
    Each time the user switches between images, the applet will probably want to implement a policy that says "that last image should be kept in memory if possible, since the user might return to it and they won't want another long delay to load it, but if you run out of memory downloading the next image, feel free to discard the first, because the next is more important." (Furthermore, your workflow might permit you to prioritise images.)
    In order to indicate to the JVM that the first image is disposable, you must clear all strong references to it. However, this simply makes it eligible for garbage collection: simple as that. You have no control over whether the garbage collector will clean that image data (which takes several seconds to retrieve) or a bunch of other data which is completely useless or can be recreated in milliseconds. Also note that in practice, weak and soft references do not actually encourage the GC to retain the data: it is cleared long before the memory is actually required.
    Note, too, that the suggestion of tweaking the heap allocation is no use for an applet (unless you have a very small, very knowledgeable and very tolerant user base).

  • JList with aligned pictures

    What would be the best way to make a JList with a picture for each item?
    I have all the pictures loaded as ImageIcons btw.

    Write a custom list renderer, see http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/ListCellRenderer.html
    Then, to get the text aligned, you'll need to use the setIconTextGap method of JLabel. If the maximum icon width is 16 and your current icon is 13 pixels wide, then just set the icon-text-gab to 3.
    Something like this:
    import java.awt.*;
    import javax.swing.*;
    public class Dummy
         public static void main(String [] args)
              JList list = new JList(new Object[]{
                   new JLabel("small", new ImageIcon("d:/java/resources/java logo 16x16.png"), JLabel.LEFT),
                   new JLabel("large", new ImageIcon("d:/java/resources/java logo 32x32.png"), JLabel.LEFT)
              list.setCellRenderer(new MyCellRenderer());
              JFrame f = new JFrame();
              f.getContentPane().add(list);
              f.setSize(400,400);
              f.setVisible(true);
         static class MyCellRenderer extends JLabel implements ListCellRenderer
              public MyCellRenderer()
                   setOpaque(true);
              public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
                   JLabel label = (JLabel)value;
                   setText(label.getText());
                   setIconTextGap(4 + 32 - label.getIcon().getIconWidth());
                   setIcon(label.getIcon());
                   setBackground(isSelected ? Color.red : Color.white);
                   setForeground(isSelected ? Color.white : Color.black);
                   return this;

  • JList(remove)

    Hi,
    I want add an remove strings from JList on run time. I have an array assigned to JList
    fileList.setListData(fileNames);
    Then I am getting the name of a node form tree
    Then compare it try to remove it. Seems like nothing happening
    TreePath currentSelection = tree.getSelectionPath();
    String tmp=currentSelection.toString();
    for(int i=0; i<=fileCount; i++)
    if(tmp==fileNames){
    fileNames[i]=null;
    while(i<fileCount){
    fileNames[i]=fileNames[i+1];
    i++;
    fileNames[fileCount]=null;
    fileCount--;
    Cold you tell me how can I correct this?

    Your code (plus my comments):
    TreePath currentSelection = tree.getSelectionPath();
    String tmp=currentSelection.toString();
    for(int i=0; i<=fileCount; i++)
        if(tmp==fileNames){
    fileNames[i]=null; //not needed, will be overwritten anyway
    while(i<fileCount){
    fileNames[i]=fileNames[i+1];
    i++;
    fileNames[fileCount]=null;
    fileCount--;
    OK, it makes a little more sense now.
    try doing jList.setListData(fileNames);

  • Setting application default font

    I have tried to search the Sun Java site for detailed info on this but haven't got anywhere.
    I have an application (Java 1.3) which will be hosted on a UNIX JVM, but displayed on a Windows2000 m/c. The only LookAndFeel available is the Metal one, and the default font is a rather chunky Dialog font.
    I want a font more like the W2000 font (arial or helvetica I think).
    Is it possible to change this in the UIManager/LookAndFeel?
    I have seen some talk in similar threads about discovering font property keys, thne using these to ally a Font object to a certain class of component (e.g labels, panels etc).
    Has anyone done anything similar, and if so can you please spell it out for me!
    Kind regards,
    Dave

    I took a little bit from both of the examples and I put together a new class that allows the user to choose what font to apply to all or, individual components. I thought that it might be helpful to other people.
    enjoy :)
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: NeoCore Inc</p>
    * <p>Based on code by: Andrew Malcolm</p>
    * @author Sandor Dornbush
    * @version 1.0
    package com.neocore.xmsApp;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.plaf.*;
    public class PLAFTest extends JFrame {
    JPanel main = new JPanel();
    JLabel jLabel1 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JButton exampleButton = new JButton();
    JPanel jPanel2 = new JPanel();
    JScrollPane m_jScrollPaneFonts = new JScrollPane();
    JList fontsList = new JList();
    JButton applyButton = new JButton("Apply");
    ButtonGroup buttonGroup1 = new ButtonGroup();
    JRadioButton m_jRadioButtonPlain = new JRadioButton();
    JRadioButton m_jRadioButtonBold = new JRadioButton();
    JRadioButton m_jRadioButtonItalic = new JRadioButton();
    JTextField m_jTextFieldSize = new JTextField();
    JLabel jLabel2 = new JLabel();
    private String[] components;
    JList componentList = new JList();
    public PLAFTest() {
    try {
    layoutComponents();
    addActionListeners();
    catch(Exception e) {
    e.printStackTrace();
    pack();
    GraphicsEnvironment graphicsEnvironment=GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames=graphicsEnvironment.getAvailableFontFamilyNames();
    fontsList.setListData(fontNames);
    UIDefaults defaults = UIManager.getDefaults();
    // Build of Map of attributes for each component
    Enumeration enum = defaults.keys();
    Vector v = new Vector();
    v.add("All");
    for(int i=1; enum.hasMoreElements(); i++) {
    Object key = enum.nextElement();
    String key_s = key.toString();
    if(key_s.endsWith(".font") &&
    !key_s.startsWith("class") &&
    !key_s.startsWith("javax")) {
    int index = key_s.indexOf(".font");
    String s = key_s.substring(0,index);
    v.add(s);
    components = (String[]) v.toArray(new String[0]);
    componentList.setListData(components);
    m_jTextFieldSize.setText("12");
    m_jRadioButtonPlain.setSelected(true);
    void this_windowClosing(WindowEvent e) {
    close();
    void close() {
    System.exit(0);
    public static void main(String[] args) {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    FontUIResource font=(FontUIResource)UIManager.get("TextField.font");
    PLAFTest plafTest=new PLAFTest();
    if( font.isPlain()) plafTest.setTitle("PLAF "+font.getFontName()+" "+font.getSize()+" PLAIN");
    if( font.isBold()) plafTest.setTitle("PLAF "+font.getFontName()+" "+font.getSize()+" BOLD");
    if( font.isItalic()) plafTest.setTitle("PLAF "+font.getFontName()+" "+font.getSize()+" ITALIC");
    plafTest.show();
    catch(Exception e) {
    e.printStackTrace();
    private void layoutComponents() {
    JPanel content = (JPanel)getContentPane();
    content.setLayout(new BorderLayout());
    JPanel top = new JPanel(new GridLayout(1,3));
    // pick the font
    m_jScrollPaneFonts.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    m_jScrollPaneFonts.setBorder(BorderFactory.createTitledBorder("Choose Font:"));
    top.add(m_jScrollPaneFonts);
    m_jRadioButtonPlain.setText("Plain");
    m_jRadioButtonBold.setText("Bold");
    m_jRadioButtonItalic.setText("Italic");
    // pick the component to apply it to
    JScrollPane scrolls = new JScrollPane(componentList);
    scrolls.setBorder(BorderFactory.createTitledBorder("Choose Component to Apply to:"));
    top.add(scrolls);
    // all of the example components
    JPanel examples = new JPanel(new GridLayout(0,1));
    jLabel1.setText("Label");
    examples.add(jLabel1);
    jTextField1.setText("TextField");
    examples.add(jTextField1);
    examples.add(exampleButton);
    exampleButton.setText("Button");
    examples.setBorder(BorderFactory.createEtchedBorder());
    top.add(examples);
    content.add(top,"Center");
    // all the stuff on the bottom
    JPanel bottom = new JPanel(new FlowLayout(FlowLayout.LEFT));
    bottom.add(m_jRadioButtonItalic);
    bottom.add(m_jRadioButtonBold);
    bottom.add(m_jRadioButtonPlain);
    bottom.add(applyButton);
    bottom.add(jLabel2);
    bottom.add(m_jTextFieldSize);
    content.add(bottom,"South");
    m_jScrollPaneFonts.getViewport().add(fontsList, null);
    buttonGroup1.add(m_jRadioButtonItalic);
    buttonGroup1.add(m_jRadioButtonBold);
    buttonGroup1.add(m_jRadioButtonPlain);
    private void addActionListeners() {
    this.addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    this_windowClosing(e);
    applyButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    applyButtonActionPerformed(e);
    void applyButtonActionPerformed(ActionEvent e) {
    try {
    Object o =fontsList.getSelectedValue();
    if(o==null)
    return;
    String fontname=(String)o;
    o = componentList.getSelectedValue();
    if(o==null){
    return;
    String componentName = (String)o;
    int fontsize=12;
    try {
    fontsize=Integer.parseInt(m_jTextFieldSize.getText());
    } catch(Exception ex) {
    ex.printStackTrace();
    return;
    int fontstyle=Font.PLAIN;
    if(m_jRadioButtonPlain.isSelected()) {
    fontstyle=Font.PLAIN;
    else if(m_jRadioButtonBold.isSelected()) {
    fontstyle=Font.BOLD;
    else if(m_jRadioButtonItalic.isSelected()) {
    fontstyle=Font.ITALIC;
    FontUIResource font=new FontUIResource(fontname,fontstyle,fontsize);
    if(componentName.equals("All")) {
    for(int i=1; i<components.length; i++)
    UIManager.put( components[i] + ".font",font);
    } else {
    UIManager.put( componentName + ".font",font);
    switch(fontstyle) {
    case Font.PLAIN: setTitle("PLAF "+fontname+" "+fontsize+" PLAIN"); break;
    case Font.BOLD: setTitle("PLAF "+fontname+" "+fontsize+" BOLD"); break;
    case Font.ITALIC: setTitle("PLAF "+fontname+" "+fontsize+" ITALIC"); break;
    SwingUtilities.updateComponentTreeUI(this);
    catch(Exception ex) {
    ex.printStackTrace();
    }

  • JScrollpane, scroll to selected element

    I have a JList of years inside a JScrollPane. The size of the scrollpane is the height of one row, so you can only see one year at a time. If the selected element in the list is changed, I want the ScrollPane to move to the selected element.
    It was suggested to me that I use the methods
    scrollRectToVisible()
    and
    getCellBounds()
    but I can't get that to work.
    Here is just a rough bit of code using these functions:
    import java.awt.*;
    import javax.swing.*;
    public class test {
         public static void main(String[] args) {
              JList selectYear;
              DefaultListModel selectYearModel;
              JScrollPane selectYearScrollPane;
              selectYearModel = new DefaultListModel();
              selectYear = new JList(selectYearModel);
              selectYear.setFixedCellHeight(25);
              selectYearScrollPane = new JScrollPane(selectYear);
              selectYearScrollPane.setPreferredSize( new Dimension(100, 25) );
              for(int i=1800; i<2200; i++) {
                   selectYearModel.addElement(""+i);
              selectYear.setSelectedIndex(5);
              selectYearScrollPane.scrollRectToVisible( selectYear.getCellBounds(selectYear.getSelectedIndex(), selectYear.getSelectedIndex()) );
              JFrame myFrame = new JFrame();
              myFrame.setVisible(true);
              myFrame.add(selectYearScrollPane);
              myFrame.pack();
    }If you run this you will see that the selected index is not scrolled to.

    I have a JList of years inside a JScrollPane. The
    size of the scrollpane is the height of one row, so
    you can only see one year at a time.Then you shouldn't use a JList. A JSpinner seems more appropriate.
    If the selected
    element in the list is changed, I want the ScrollPane
    to move to the selected element.
    It was suggested to me that I use the methods
    scrollRectToVisible()
    and
    getCellBounds()
    ensureIndexIsVisible(int index) might work better.

  • ISO-8859-1: %22 equals & # 3 4 ; ?

    NOTE: In this topic, & # 3 4 ; should contain no spaces. But when I remove the spaces, it automatically converts it to " , so that's why I put spaces.
    Hey all,
    Sorry for the 'difficult' topic title. I experience a problem when I try to parse HTML downloaded from imdb.com.
    I have this code to search on IMDB:
    URL imdbURL = new URL("http://us.imdb.com/Find?" + URLEncoder.encode(page1.getSearch(), "ISO-8859-1"));Then, I parse the incoming HTML in this bufferedreader:
    BufferedReader in = new BufferedReader(new InputStreamReader(imdbURL.openStream(), "ISO-8859-1"));Problem I experience, is that when I search for "Mr. Bean", I get a title returned called: & # 3 4 ;Mr. Bean& # 3 4 ; (when you check the website, it displays as "Mr. Bean"). So, on the website, the & # 3 4 ; is translated into " , just like the ISO-8859-1 is meant to do. But my InputStreamReader SHOULD do the same, but it doesn't.
    When I search for: " , I can see that my encoding line encoded the " into %22. So this is probably the reason it doesn't convert & # 3 4 ; into ", because it will only convert %22 into ". Does anyone know how I can solve this problem?
    Thanks in advance!!

    Thanks for your reply,
    Using the bufferedreader, I read the content line by line. At some stage, I get to this line:
    <p><b>Popular Titles</b> (Displaying 3 Results)<ol><li>  <a href="/title/tt0096657/" onclick="set_args('tt0096657',1,1)">&#34;Mr. Bean&#34;</a> (1990)</li>As you can see (or maybe not because this forum automatically parses it automatically), the title is & # 3 4 ;Mr.Bean& # 3 4; . This is also the String my JList displays when I put it in there. So what I want is, of course, that that String will replace that part with " . Of course I could achieve it using:
    sName = sName.replaceAll("& # 3 4 ;", "\"");But, maybe there are more 'codes' like this in the webpage, so I want all the html entity's to be parsed automatically.
    Hopefully I made myself clear.
    Regards,
    Peter

  • Can I add a JScrollPane in the JMenu

    I want to add a JScrollPane to the JMenu. The JScrollPane contains a JList, so that when I click on the menu the JScrollPane shows and I can select a item from the list.
    I tried for some time, but still cannot make the JScrollPane displayed yet in the menu.
    Any one can help?

    Try this it worked, I not sure if this is what you want. a few ke things worth noticing, setPreferred size on the JPanel. That might be the reason it was not showing up, anyway here it is.
    import javax.swing.*;
    import java.awt.*;
    import java.util.Vector;
    public class temp extends JFrame{
         public temp(){
              super("Scroll Test");
              Vector myVector = new Vector();
              JPanel contentPane = new JPanel(new BorderLayout());
              for(int j = 0; j < 40; j++)
                   myVector.add(new String(j + ""));
              JList theList = new JList(myVector);
              JScrollPane sp = new JScrollPane(theList);
              JPanel p = new JPanel(new BorderLayout());
              p.setPreferredSize(new Dimension(100, 100));
              JMenuBar menuBar = new JMenuBar();
              JMenu menu = new JMenu("Scroll");
              p.add(sp, BorderLayout.CENTER);
              menu.add(p);
              menuBar.add(menu);
              this.setJMenuBar(menuBar);
              this.setContentPane(contentPane);
              this.setSize(300, 300);
         public static void main(String [] args){
              JFrame j = new temp();
              j.show();
    Good luct write back and tell me if this is what you were looking for!
    Late jason

  • Can I Add a memo in the E61i calendar that repeats...

    Can I Add a memo in the E61i calendar that repeats weekly?

    Try this it worked, I not sure if this is what you want. a few ke things worth noticing, setPreferred size on the JPanel. That might be the reason it was not showing up, anyway here it is.
    import javax.swing.*;
    import java.awt.*;
    import java.util.Vector;
    public class temp extends JFrame{
         public temp(){
              super("Scroll Test");
              Vector myVector = new Vector();
              JPanel contentPane = new JPanel(new BorderLayout());
              for(int j = 0; j < 40; j++)
                   myVector.add(new String(j + ""));
              JList theList = new JList(myVector);
              JScrollPane sp = new JScrollPane(theList);
              JPanel p = new JPanel(new BorderLayout());
              p.setPreferredSize(new Dimension(100, 100));
              JMenuBar menuBar = new JMenuBar();
              JMenu menu = new JMenu("Scroll");
              p.add(sp, BorderLayout.CENTER);
              menu.add(p);
              menuBar.add(menu);
              this.setJMenuBar(menuBar);
              this.setContentPane(contentPane);
              this.setSize(300, 300);
         public static void main(String [] args){
              JFrame j = new temp();
              j.show();
    Good luct write back and tell me if this is what you were looking for!
    Late jason

Maybe you are looking for

  • [10.8.4, mid-2010 MBP] Finder icons flashing, sending messages of crashing.  Confirmed in console.  Help.

    I've seen some mention of this problem here, there, and everywhere, but no solutions.  The skinny: Mid-2010 MBP with a recent logic board replacement (dead GPU).  Desktop icons disappearing, reappearing every three minutes or so. Popup saying that la

  • How to automate dates in a Quest Powershell script?

    Hi I have this script: Add-PSSnapin Quest.ActiveRoles.ADManagement Get-QADUser -SizeLimit 0 -CreatedAfter (Get-Date 12/12/2013) -CreatedBefore (Get-Date 13/12/2013) -IncludedProperties Name,WhenCreated,DisplayName,EMail,EmployeeID,StreetAddress,WebPa

  • How to add Profile Picture in Jabber

    I would like to ask, how to add profile picture in Jabber ? For your information, my callmanager with 10.5.1.10000-7 version have been integrated with Active Directory in Windows Server 2008 Thanks and Best Regads, Ferly

  • HT2506 PDF issues

    Since installing Adobe, I have had trouble with my IMac opening PDF files.  Any ideas?

  • Is it possible to have mm/yy format?

    Hi, In our application, we need only month and year. I checked DateFormat class and it expects dd/mm/yy. I don't know how to parse string if user enters mm/yy. Thx for help in advance!