Solved

a JTable problem

Posted on 2001-07-23
14
205 Views
Last Modified: 2008-03-10
Hi
I want my table to always have a horizontal scroll bar
but somehow when I maximize the applet the scroll bar
disappears.How Can I force the scroll bar to always
exist.


I have tried setting the policy but doesnot seem to work

This is the code

   EvLogData evLogData   = new  EvLogData();
   Object [][] data      = EvLogData.getData();
   String [] colNames    = EvLogData.getColumns();


   NoEditTableModel tabModel = new NoEditTableModel  
                        (data,colNames);

   evLogTable   = new JTable(tabModel); //define the table
   evLogTable.setBackground(Color.lightGray);
   evLogTable.setShowGrid(false);
   JScrollPane evTablePane   = new JScrollPane
                        (evLogTable);

   evTablePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    JPanel evP = new JPanel();
    evP.setLayout(new BoxLayout(evP,BoxLayout.Y_AXIS));
    evP.add(evTablePane);
    evP.setAlignmentX(Box.LEFT_ALIGNMENT);


    evP.setPreferredSize(new Dimension(400,100));
    evP.revalidate();
    evP.repaint();


p.s : actually it shows the end arrows but there is  
      nothing to scroll  something like
      an empty scroll bar



0
Comment
Question by:sanjay_thakur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
  • +2
14 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6310676
sanjay,

24 questions asked,
Only 6 questions graded (and 5 C's awarded).

You can't be getting that bad advice can you?

> actually it shows the end arrows but there is  
> nothing to scroll  something like
> an empty scroll bar

Well if the table fits on the panel, and there's nothing to scroll then what would you expect?





0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6310997
Hi,
I apologize!
I have been bit clumsy
but as you can see I have promptly acted !

now back to the question

>Well if the table fits on the panel, and there's nothing >to scroll then what would you expect?

That's why I need a solution

because I want to make the table like "event viewer"
refer :control panel --> administrative tools (windows)

There is always a "horizontal scroll bar"

I dont know how to achieve this
so that even if the table fits in the panel
the scroll bar exists

0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6311001
Hi,
I apologize!
I have been bit clumsy
but as you can see I have promptly acted upon your comment
!

now back to the question

>Well if the table fits on the panel, and there's nothing >to scroll then what would you expect?

That's why I need a solution

because I want to make the table like "event viewer"
refer :control panel --> administrative tools (windows)

There is always a "horizontal scroll bar"

I dont know how to achieve this
so that even if the table fits in the panel
the scroll bar exists

0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 92

Expert Comment

by:objects
ID: 6311443
> I have promptly acted upon your comment

Thank you very much :)

> because I want to make the table like "event viewer"

I just looked at Event Viewer on W2K and it disappears when not needed.

To do what you want you just need to make the size of the scrolled component bigger than the viewport. Try setting the width of your table to a large number.


0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6313560
hi,

I added this
evLogTable.setPreferredSize(new Dimension(screenSize));

but the problem is

the table columns are resized by default to fit in the
available space hence there is no scroll bar

I tried
evLogTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

but this leads to many problems

like I cannot size the columns properly.

How can I add scrollbar without
this
evLogTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

HElp!!!

0
 

Expert Comment

by:rwoodruf
ID: 6313844
sanjay,

Try this:

JScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

Please grade if this works.

Hope this helps.

-- Rodney
0
 

Expert Comment

by:rwoodruf
ID: 6313856
Sanjay,

I mean to say:

evTablePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

-- Hope this helps.
0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6313878
I already have this in my code

if u refer the code posted

This doesn't work.

0
 

Expert Comment

by:rwoodruf
ID: 6313899
So you're saying that you want the scrollbar to be active whether it is needed or not?  You want to be able to scroll no matter the circumstance.

If this is the case, then there is absolutely no way to do this.  Can I ask why you would want a active scrollbar when there is nothing that needs to be scrolled?

-- Rodney
0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6315744

ok I rephrase the question

if I set table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF)
I am able to get
the scrollbar but there is a gap left
between the rightmost boundary of the table and the last column.

How do I remove this gap.

p.s: How can I know the current size of the applet
for example if the user changes the size of the applet is there
any way/event to know that change







0
 
LVL 4

Accepted Solution

by:
kylar earned 30 total points
ID: 6319150
You can set a component listener and catch Component Resize events.
 if you have a JTable that doesn't take up all the room in a scrollpane (because the column widths don't fill the space) then you will always get the empty space. You can re-size the JScrollPane instead, and make sure that it fits the JTable (with a little munging), but you don't really have too many options here.

Kylar
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6956133
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20180059.html
http://www.experts-exchange.com/questions/Q.20221686.html
http://www.experts-exchange.com/questions/Q.20234788.html
http://www.experts-exchange.com/questions/Q.20246190.html
http://www.experts-exchange.com/questions/Q.20256943.html
http://www.experts-exchange.com/questions/Q.20257803.html
http://www.experts-exchange.com/questions/Q.20257760.html
http://www.experts-exchange.com/questions/Q.20260496.html
http://www.experts-exchange.com/questions/Q.20263573.html
http://www.experts-exchange.com/questions/Q.20263541.html
http://www.experts-exchange.com/questions/Q.20266174.html
http://www.experts-exchange.com/questions/Q.20283765.html
http://www.experts-exchange.com/questions/Q.20288327.html
http://www.experts-exchange.com/questions/Q.20291180.html
http://www.experts-exchange.com/questions/Q.20291602.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20155817.html
http://www.experts-exchange.com/questions/Q.20169826.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6961062
Hi I would like to accept kylars solution as the answer

0
 
LVL 4

Author Comment

by:sanjay_thakur
ID: 6961067
Hi I have accepted kylars solution as the answer

I couldnot get anything else work

I still dont think that this is a neat solution
but this is the one that works

Thanks everyone
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Eclipse Java import and method not resolved 4 135
jmeter usage 4 66
Java Inheritance super keyword use 8 73
Setup Eclipse for Andriod development 2 20
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question