Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

a JTable problem

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
sanjay_thakur
Asked:
sanjay_thakur
  • 7
  • 3
  • 2
  • +2
1 Solution
 
objectsCommented:
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
 
sanjay_thakurAuthor Commented:
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
 
sanjay_thakurAuthor Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
> 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
 
sanjay_thakurAuthor Commented:
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
 
rwoodrufCommented:
sanjay,

Try this:

JScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

Please grade if this works.

Hope this helps.

-- Rodney
0
 
rwoodrufCommented:
Sanjay,

I mean to say:

evTablePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

-- Hope this helps.
0
 
sanjay_thakurAuthor Commented:
I already have this in my code

if u refer the code posted

This doesn't work.

0
 
rwoodrufCommented:
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
 
sanjay_thakurAuthor Commented:

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
 
kylarCommented:
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
 
MoondancerCommented:
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
 
sanjay_thakurAuthor Commented:
Hi I would like to accept kylars solution as the answer

0
 
sanjay_thakurAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now