JTable help Urgent need !!!!!

hi, I am having problem in getting scrollBar arround my JTextArea that's in a cell of my JTable. If you run the following two files and see the output. The second cell should show me the scrollBars as the whole text is not visible. Please look at the code and see where I am doing wrong. I need to have scrollBars appear arround my individual JTextArea if the text doesn't fit in it. Any help is appreciated...
/****** This is the main file ***********/
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class MultiLineCellExample extends JFrame
public MultiLineCellExample()
super( "Multi-Line Cell Example" );
DefaultTableModel dm = new DefaultTableModel() {
public Class getColumnClass(int columnIndex) {
return String.class;
dm.setDataVector(new Object[][]{{"2"},{" Error 1Error 1Error 1Error 1Error 1Error 1 Error 1Error 1Error 1Error 1 Error 1Error 1Error 1 Error 1Error 1Error 1Error 1Error 1Error 1 Error 1Error 1Error 1Error 1Error 1Error 1Error 1"}},
new Object[]{"Following are the Errors"});
JTable table = new JTable( dm );
int lines = 2;
table.setRowHeight( table.getRowHeight() * lines);
table.setDefaultRenderer(String.class, new TextCellRenderer());
JScrollPane scroll = new JScrollPane( table );
getContentPane().add( scroll );
setSize( 400, 130 );
setVisible(true);
public static void main(String[] args)
MultiLineCellExample frame = new MultiLineCellExample();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
/********* This is the TableCellRenderer file **********/
/* this code is from
Copyright (c) 1999 Computer Engineering and Communication Networks Lab (TIK)
Swiss Federal Institute of Technology (ETH) Zurich, Switzerland
All rights reserved.
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this
software and its documentation for any purpose, provided that the above
copyright notice and the following two paragraphs appear in all copies
of this software.
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import javax.swing.border.*;
import javax.swing.table.*;
import java.awt.Component;
import java.awt.Color;
import java.io.Serializable;
public class TextCellRenderer extends JTextArea
implements TableCellRenderer, Serializable{   //,Scrollable{  Need to implement this too to get scrolls on individual JtextAreas too.
                                                                                //currently not working, have to look into too.     
protected static Border noFocusBorder;
private Color unselectedForeground;
private Color unselectedBackground;
public TextCellRenderer() {
     super();
noFocusBorder = new EmptyBorder(1, 1, 2, 1);
          this.setOpaque(true);
this.setBorder(noFocusBorder);
this.setColumns(6);
this.setWrapStyleWord(true);
          this.setLineWrap(true);
          this.setAutoscrolls(true);
          //this is not working yet, trying to figure out some other way
     JScrollPane pane = new JScrollPane( this,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                  JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
public void setForeground(Color c) {
super.setForeground(c);
unselectedForeground = c;
public void setBackground(Color c) {
super.setBackground(c);
unselectedBackground = c;
public void updateUI() {
super.updateUI();
          setForeground(null);
          setBackground(null);
JTable table;
// implements javax.swing.table.TableCellRenderer
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
this.table = table;
     if (isSelected) {
     super.setForeground(table.getSelectionForeground());
     super.setBackground(table.getSelectionBackground());
     else {
     super.setForeground((unselectedForeground != null) ? unselectedForeground
     : table.getForeground());
     super.setBackground((unselectedBackground != null) ? unselectedBackground
     : table.getBackground());
     setFont(table.getFont());
     if (hasFocus) {
     setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
     if (table.isCellEditable(row, column)) {
     super.setForeground( UIManager.getColor("Table.focusCellForeground") );
     super.setBackground( UIManager.getColor("Table.focusCellBackground") );
     } else {
     setBorder(noFocusBorder);
setValue(value);
     return this;
protected void setValue(Object value) {
     setText((value == null) ? "" : value.toString());
if (table != null) {
String s = getText();
//count the number of returns
int ind = 0;
//add an extra line for the scroll bar if required
int num = 2;
do {
ind = s.indexOf("\n", ind);
if (ind >= 0) {
num++;
ind++;
} while (ind > 0);
//set the row height to fit in this cell
int newHeight = (table.getFont().getSize()*9*num)/5;
if (table.getRowHeight() < newHeight) {
table.setRowHeight(newHeight);
public static class UIResource extends DefaultTableCellRenderer
implements javax.swing.plaf.UIResource
public Dimension getPreferredScrollableViewportSize()
          return this.getPreferredSize();      
     public int getScrollableBlockIncrement(Rectangle r, int orietation, int direction)
          return 10;      
     public boolean getScrollableTracksViewportHeight()
          return false;      
     public boolean getScrollableTracksViewportWidth()
          return false;      
     public int getScrollableUnitIncrement(Rectangle r, int orientation, int direction)
          return 10;      

Hi,
You want to have a cell in the JTable with a JTextfield and a JScrollBar??? Can you specify and put the source code enclose in   JRG

Similar Messages

  • Help urgently needed, I have installed Logic Pro 9, since then my Final Cut Pro X keep freezing. Anyone what is wrong and how to solve it? I desperately need help on this. Thanks

    Help urgently needed, I have installed Logic Pro 9, since then my Final Cut Pro X keep freezing. Anyone what is wrong and how to solve it? I desperately need help on this. Apple support says I have to pay £85 for to help me. Thanks

    Just a word of advice. Never ever use the word "urgent" on this forum

  • Help urgently needed please ! My Iphone 4 is on silent vibration mode, received a call and has frozen with the Iphone unusable and yet vibrating. I have tried switching off, connecting to power, connecting to laptop and removing SIM card ???

    Help urgently needed please ! My Iphone 4 is on silent vibration mode, received a call and has frozen with the Iphone unusable and yet vibrating. I have tried switching off, connecting to power, connecting to laptop and removing SIM card ???

    Problem solved... just saw the answer in another thread... https://discussions.apple.com/message/13110222#13110222

  • HELP urgently needed: My Sandberg FireWire for Laptop will not start on my T60

    Let me start with information on my T60:
    OS information: Microsoft Windows XP
    OS version: 5.10.2600   Service Pack 2
    Processor: x86 Family 6 Model 14 Stepping 8
    Memory: 3.135.856 kb
    BIOS version: 2.09  (79ETC9WW)
    Machine type-Model: 1951A47
    I have just got a new Sandberg FireWire for Laptop, a PC Card with 3 6-pins connectiont. After inserting the card in the PC Card slot, the Windows Device Manager tells me that there are problems with the card. Looking at the 1394 Card Properties the status says:
    "This device cannot start. (Code 10) - Click Troubleshoot to start the troubleshooter for this device."
    The troubleshooter did not solve my problem. I have tried disconnecting, re-connection, shut down Windows and start again etc.
    At Sandberg Help Desk they tell me that I have two slots in my laptop, one with a 16 bits bus and another with a 32 bits slots, and I should use the latter. It seems that I can use the lower slide only in my laptop and I cannot push the card into the upper slide. There is not enough room for it.
    Here is what I found on Lenovo's support site on my type & model:
     PC Card
    Conforms to the PC Card Standard 95
    Type II slot
    Both the 16-bit Release 2.1 card standard and the 32-bit CardBus card are supported.
    Have a look at these screen captures.
    What should I do to solve my urgent problem!? 
    Message Edited by pbl_ibm on 10-09-2008 05:10 AM
    Message Edited by pbl_ibm on 10-09-2008 07:27 AM
    Message Edited by pbl_ibm on 10-09-2008 07:45 AM
    Message Edited by pbl_ibm on 10-09-2008 07:45 AM

    garytr23 wrote:
    Sounds to me like a driver configuration problem.  Maybe something bad happened during driver install.  I would recommend uninstalling the device from device manager by right clicking on it and hitting uninstall.  Reboot the computer.  Have a go at it again.  Also, test your pcmcia port functionality by finding and plugging in a different card.  See if that works.  It might need repair.
    Message Edited by garytr23 on 10-09-2008 09:41 AM
    The status right now is:
    The PC Card reader works on my T60
    If I use a Firewire PC Card it will not start - as described above (on T60)
    The PC Card work properly on my T61P - and I succeeded importing a video file from a digital camera using the Fireswire PC Card.
    So what does a wise man do in this situation??
    Please help me as I urgently need to know how to solve this serious issue!! 
    Have you got an idea? Can I import the video in another way??
    Message Edited by perbuch on 10-12-2008 07:55 AM

  • Help urgently needed with Java RMI task.

    Hello All. Please I need help urgently with this task. I cant seem to be able to do this. Here is the task:
    There are m squares with side lengths a1, a2, ..., am and a rectangle with the height and width equal to h and w respectively. Find a subset of the squares, which must be placed within the rectangle in such a way that they do not overlap, and cover the maximum area of a rectangle.*
    Please all help me solve this task using Java RMI. I would be very grateful for your help. Thanks in advance.

    Here is my client.java.
    import compute.;*
    import java.lang.Math.;*
    import java.lang.Long;
    *public class Hypothesis implements Task {*
    private long start;
    private long end;
    private int number;
    private int count;
    public Hypothesis(long start, long end, int number,int
    *count) {*
    this.start = start;
    this.end = end;
    this.number = number;
    this.count = count;
    *public Object execute() {*
    return findSolution();
    *public String findSolution() {*
    long i,j,k,l,m=1,i_max,j_max,k_max,l_max,l_start;
    System.out.println(start);
    System.out.println(end);
    System.out.println(number);
    System.out.println(count);
    for(m=start+number;m<end;m+=count)
    i_max=(long)java.lang.Math.pow((double)(min(p5(m)-3)),0.2d)+1;
    for(i=i_max;i>0;i--)
    j_max=(long)java.lang.Math.pow((double)(min(p5(m)-p5(i)-2)),0.2d)+1;
    if (j_max>i) j_max=i;
    for(j=j_max;j>0;j--)
    k_max=(long)java.lang.Math.pow((double)(min(p5(m)-p5(i)-p5(j)-1)),0.2d)+1;
    if (k_max>j) k_max=j;
    for(k=k_max;k>0;k--)
    l_max=(long)java.lang.Math.pow((double)(min(p5(m)-p5(i)-p5(j)-p5k))),0.2d)+1;
    if (l_max>k) l_max=k;
    if (l_max>2) l_start=l_max-2;
    else l_start=1;
    for(l=l_max;l>l_start-1;l--)
    if(p5(i)+p5(j)+p5(k)+p5(l)==p5(m))
    Long[] solution=new Long[5];
    solution[0]=i;
    solution[1]=j;
    solution[2]=k;
    solution[3]=l;
    solution[4]=m;
    *return "" solution[0]"^5+"*
    solution[1]"^5+"*
    solution[2]"^5+"*
    solution[3]"^5="*
    solution[4]"^5";*
    return null;
    *private long p5(long n){*
    return nn*n*n*n;*
    *private long min(long n){*
    return n>0?n:0;
    I just can't seem to get the whole thing work correctly on the server side. I need it to run from 1 client on atleast 3 servers. Please any explanations will be appreciated.

  • Installation problem, please help, urgent needs,

    I have install the FCP 7 into my MBP, and updated, but in the "add behavior" tap i don't have those new behavior like "text-basic" "text-continuous" "text-energetic" etc..... how can i add it back?
    urgent needs, please help

    fixed

  • Help urgently needed: bizarre problem - no audio in imported clip!

    Hey there!
    I have a bizarre - never the less urgent problem:
    When I import some material (presentations) which I have recorded on Mini DV with my Canon MVX10i Camcorder the following problem occurs:
    There is one particular presentation which somehow looses the audio during the import process!
    That means the imported clip has no audio even though the audfio is on tape! Other clips before and after do not have this problem - the audio is available after the import.
    A bizarre but serious problem for me. Any suggestions?
    Thanks a lot in advance
    Thorge

    I had a similar problem. When I started the tape from the beginning no audio would import. To solve it I started the tape a few seconds in and It seemed to work.
    Hope this helps.

  • Help urgently needed with xml reading

    hi, i have a 3gig xml file which i am surprised it is so large as i have even shortened all of the names,
    it contains 2000 elements which have a filename and an array, each element has an array of size 6000, and each element in this array has an array of shorts, say 100 of them, and also a filename.
    i ahve used stax writing to be able to write such a large file without having memory problems.
    i then had to program a stax reader to be able to read it all in without building the whole tree but with some large cases i am now getting out of memory again, it seems to eb from the read so maybe the code eve though it doesnt have to hold the tree in memory, it has to hold the file in memory, the code for reading is shown here:
    package utilities;
    import Categorise.Collection;
    import Categorise.Comparison;
    import Categorise.TestCollection;
    import java.io.IOException;
    import javax.xml.parsers.*;
    import org.xml.sax.SAXException;
    import org.xml.sax.helpers.DefaultHandler;
    import org.xml.sax.Attributes;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    import measures.Protocol;
    * @author dthomas
    public class XMLParser extends DefaultHandler
        static Collection collection = new Collection();
        List<Short> cList;
        List<Comparison> comparisonList;
        File trainFileName;
        File testFileName;
        TestCollection tc;
        List<TestCollection> testCollectionList;
        List<File> testFileNameList = new ArrayList<File>();
        List<File> trainFileNameList = new ArrayList<File>();
        boolean allTrainsAdded = false;
        Protocol protocol;
        List<File> trainingDirList;
        File testingDir;
        int counter = 0;
        /** Creates a new instance of XMLParser */
        public XMLParser() {
        public static Collection read( File aFile )
            long startTime = System.currentTimeMillis();
            System.out.println( "Reading XML..." );
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp;
            try {
                sp = spf.newSAXParser();
                sp.parse( aFile, new XMLParser() );
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (SAXException ex) {
                ex.printStackTrace();
            } catch (ParserConfigurationException ex) {
                ex.printStackTrace();
            long endTime = System.currentTimeMillis();
            long totalTime = ( endTime - startTime ) / 1000;
            System.out.println( "Done..."  + totalTime + " seconds" );
            return collection;
        public void startElement(String uri,String localName,String qName, Attributes attributes)
            if( qName.equals( "RE" ) )
                testCollectionList = new ArrayList<TestCollection>();
            else if( qName.equals( "p") )
                boolean isConcatenated = new Boolean( attributes.getValue( "c" ) );
                boolean isStatic = new Boolean( attributes.getValue( "s" ) );
                protocol = new Protocol( isConcatenated, isStatic );
            else if( qName.equals( "trdl" ) )
                trainingDirList = new ArrayList<File>();
            else if( qName.equals( "trd" ) )
                File trainDir = new File( attributes.getValue( "fn" ) );
                trainingDirList.add( trainDir );
            else if( qName.equals( "td" ) )
                testingDir = new File( attributes.getValue( "fn" ) );
            else if( qName.equals( "TC" ) )
                counter++;
                System.out.println( counter );
                comparisonList = new ArrayList<Comparison>();
                testFileName = new File( attributes.getValue( "tfn" ) );
                testFileNameList.add( testFileName );
                tc = new TestCollection( );
                tc.setTestFileName( testFileName );
            else if ( qName.equals( "r" ) )
             String order = attributes.getValue( "o" );
                String type = attributes.getValue( "t" );
                String value = attributes.getValue( "v" );
                cList.add( Short.parseShort( order ), new Short( value ) );
            else if( qName.equals( "c" ) )
                cList = new ArrayList<Short>();
                trainFileName = new File( attributes.getValue( "trfn" ) );
                if( !allTrainsAdded )
                    trainFileNameList.add( trainFileName );
        public void characters(char []ch,int start,int length)
            String str=new String(ch,start,length);
            System.out.print(str);
        public void endElement(String uri,String localName,String qName)
            if (qName.equals( "c") )
                allTrainsAdded = true;
                short[ ] cCounts = new short[ cList.size() ];      
                for( int i = 0; i < cCounts.length; i++ )
                    cCounts[ i ] = cList.get( i );
                Comparison c = new Comparison( trainFileName, tc );
                c.setcCounts( cCounts );
                this.comparisonList.add( c );
            else if( qName.equals( "TC" ) )
                Comparison[ ] comparisons = new Comparison[ comparisonList.size() ];
                comparisonList.toArray( comparisons );           
                tc.setComparisons( comparisons );
                testCollectionList.add( tc );
            else if( qName.equals( "RE" ) )
                TestCollection[ ] testCollections = new TestCollection[ testCollectionList.size() ];
                testCollectionList.toArray( testCollections );
                collection.setTestCollections( testCollections );
                File[ ] testFileNames = new File[ testFileNameList.size() ];
                testFileNameList.toArray( testFileNames );
                collection.setTestingFiles( testFileNames );
                File[ ] trainingFileNames = new File[ trainFileNameList.size() ];
                trainFileNameList.toArray( trainingFileNames );
                collection.setTrainingFiles( trainingFileNames );
                collection.setProtocol( protocol );
                File[ ] trainingDirs = new File[ trainingDirList.size() ];
                trainingDirList.toArray( trainingDirs );           
                collection.setTrainingDirs( trainingDirs );
                collection.setTestingDir( testingDir );
    }any help would be greatly greatly appreciated
    thanks
    Danny =)
    ps with the amount of data contained, should the xml file be this large? and does ayone know the size difference of holding a filename as a File rather than a string and then creating the file when it is needed?

    yes i do need them but i could store them as strings instead if you think that would help? if it never runs out of memory i dot see how i was able to hold all of this information in memory before, as it was all written to file.
    thanks

  • Help urgently needed

    Hi,
         Thanks for your answers. But my problem is not that. I need to develop a separate transaction code to log off all sessions or atleast that session. This transaction code will be assigned to a push button on the ESS(Employee Self Service) screen to log off. So please help me.
    Thanks in advance,
    Ramana

    Doesn't each screen in ESS have the logoff function?
    Rob

  • Help urgently needed: Iphone 5 update error

    I went into system settings to update my iphone 5 to the newer verzion of ios 7 and instead of starting the update when I clicked it, it went into recovery mode. I have so many valuble pictures on my phone I can't just restore it to factory defaults and lose all of them as well as videos. I have tried holding the on/off button and the home button for 15 seconds and it just keeps going back to the same screen. Please, please, please help. I also can't get help directly from apple this night since I cannot get into my phone to get the serial number. Please, any help is greatly appreciated.

    I am in the same situation as the original poster.  I am trying to restore the device, but my iTunes says it is downloading the software update (although it shows when my phone is *not* plugged in that the download was completed). When the "download" is not yet complete, I get a message telling me there was a problem downloading the software for the phone because the network connection failed, even though there is no problem with my wifi.  I occasionally get the random message: "iTunes has detected an iPhone in recovery mode.  you must restore this iPhone before it can be used with iTunes." I need to point out that the message is randomly received *as* I am downloading the software update to restore it.
    This is the third attempt at restoring the phone, so any advice to make this work is appreciated.

  • HELP urgently needed-software update question

    Hi.
    Just installed (20/10/12) latest updates for OSX10.7 Including printer update, Java update (removal) and osx bundle update. Upon restart, the computer won't recognise my password. It wasn't a misstype, I've tried it several times. Not quite sure what's going on. All was fine until I did the update. Any possibility I've been hacked and what's the chance my computer now has key logging on it (worried about going into admin account to check any probs).  Worried this is to do with Java somehow. I'm really security conscious (have now changed all passwords for all accounts and am accessing this from parents computer which is Java free)
    Please help, I'm moving house at the moment and really need my macbook operational!
    Yours desperately
    Kaz

    It just means that you have the latest available updates installed. If any new update is released for your phone's product code, it will automatically show on Ovi Suite if you are connected to the internet.
    If you find my post helpful please click the green star on the left under the avatar. Thanks.

  • Help urgently needed...about buttons!

    Hey guys!
    Was wondering if someone could help me out here.
    I have a selection of buttons that once clicked will play an animation. You can see what I mean by visiting my link below!
    http://robshaw.me/test/UB/AS3-535-3.html
    I only want one button to raise at a time and when you click another button the one that has already raised animates back down and the new button clicked raises up.
    I have been told that I only need three functions.
    Could anyone please please please tell me how to go about this?
    Thankyou so much in advance!
    _Rob

    Nope, no need to juggle listeners...
    var selectedMC:MovieClip = null;
    var allowPlay:Boolean = true;
    function sharedPlay(evt:MouseEvent):void {
         if(allowPlay){
             allowPlay = false;
             if(selectedMC != null){ // deal with previous selected mc
                  selectedMC.play();
             selectedMC = MovieClip(evt.currentTarget.parent);  // process current
             selectedMC.play();
    and in your movieclips in the animation stop frame you can use something like...
    MovieClip(parent).allowPlay = true;

  • Adobe Designer 7.0 - help urgently needed!

    Dear all,
    I need to create a button and add an action to it (exporting data). When creating a button at the moment, however, there are only three types of buttons I can chose from and nothing to add an action to the button!
    How do I do this!?
    Any help would be appreciated!
    regards Obritzhauser Martin

    In the Library palette's Standard tab, you'll find many different kinds of buttons: (Regular) Button, Print Button, Email Submit Button, HTTP Submit Button and Reset Button. The (Regular) Button, once on the form and selected, can be made into a submit or execute button.
    If you're wanting to have form data submitted to an email or HTTP site, I would suggest using the email or HTTP submit buttons, respectively. Just fill-out the properties in the Object palette.
    If you need to do some custom steps (pertaining to this "action" you want to add), you can do so by adding script via the Script Editor. Select the button then select the event (action) you want to add script to in the Script Editor's
    Show drop down list.
    Stefan
    Adobe Systems

  • Please help, urgently need to change DD payment Da...

    I really do not know If I am asking the right person or even whether I should be posting as new to BT but I am in trouble and need help. I have joined BT and have BB and phone, and am well pleased with it. My problem is that I am going to have my direct debit taken on 8th of the month and I desperately need to change this to the 15th  due to my salary arrangement. I can see issues each month. I know i need give 7 days notice so really need help asap. Many thanks in advance

    If you would like to try Live Chat they should be able to help you.
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • How can i fix my my iPad i downgraded it to 8.1.3 to 8.1.2 and when some error occured the iPad suddenly shut down and reopen and it only show the icon of iTunes and the connect symbol  please help urgently needed

    Hi please help me i try to downgrade my iPad ios to 8.1.3 to 8.1.2 and an error occursd and can't open my iPad only the icon of iTunes and charger appeared please help

    That means that it's gone into recovery mode - connect the iPad to your computer's iTunes and reset it back to factory defaults.
    Downgrading the iOS version isn't supported by Apple.

Maybe you are looking for

  • Acrobat 9.0 Standard Media needed

    I had to have my laptop reimaged and when that was done, my Adobe Acrobat 9.0 Standard software was not on it. I no longer have the disk but the software is registered in my name and I have the serial number. How can I get the media for Acrobat 9.0 S

  • Upgrade from DS 4.1 to DS 5.1

    Hi all we are presently running DS 4.1 on Solaris 7 on E 220 server , We came to know that Solaris 9 comes bundeled with the DS 5.1 which can be used in production setup free of cost upto 200,000 ldap entries , so we have decided to upgrade the DS se

  • Are there any good code examples for displaying preview images in the storefront?

    I can gather other info using folio.xxx, but can not find any good examples to use for preview images.  Tried folio.getPreviewImage() with no success.  Oh, I should mention it is version 2.  Plenty of examples for version 1. Perhaps if I get a little

  • Know alv grid on event click

    Hi, Is it possible to know the alv grid (TYPE REF TO cl_gui_alv_grid) on the event click? In fact, on a screen, I have 2 alv grids and I would like to store the alv grid name for a process at click moment. Thanks. Edited by: Xavier Couloumies on Sep

  • AEBS can't keep an internet connection for more than 1 day...why?

    I continually have to reset my Ethernet cable on my cable modem to get connected to the internet.This is very frustrating. I had Apple send me a new unit and that still hasn't fixed the problem. The only thing that works is printer sharing. Is anyone