Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Code Included: Freeze column

Reply
Thread Tools

Code Included: Freeze column

 
 
John B. Matthews
Guest
Posts: n/a
 
      06-05-2013
In article <1l4u82e78abn0$.1pqqndsg2e5m4$(E-Mail Removed)>,
Joerg Meier <(E-Mail Removed)> wrote:

> On Tue, 4 Jun 2013 14:17:29 -0700 (PDT), Lew wrote:
>
> > Haircuts Are Important wrote:
> >> Lew wrote:
> >>> > ┬*Haircuts Are Important wrote:
> >>> > > > For improved visual coherence, the tables can share a
> >>> > > > selection model, much as you have done with the
> >>> > > > scrollbars' BoundedRangeModel:
> >>> ...
> >>> What happened to all your posts?
> >> I'm still listening.

> > That's nice.

>
> > What happened to all your posts?

>
> If you have issues with the posts of multiple people, the issue
> might not be on their end.


With so many of clusardi2k's posts deleted, I am unable to follow
the thread:

<https://groups.google.com/forum/?fromgroups&hl=en#!topic/comp.lang.java.programmer/ze39FiJ8IDI>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      06-05-2013
Joerg Meier wrote:
> Lew wrote:
> > Haircuts Are Important wrote:
> >> Lew wrote:
> >>> > *Haircuts Are Important wrote:
> >>> > > > For improved visual coherence, the tables can share a selection
> >>> > > > model, much as you have done with the scrollbars'
> >>> > > > BoundedRangeModel:
> >>> ...

>
> >>> What happened to all your posts?

>
> >> I'm still listening.

>
> > That's nice.
> > What happened to all your posts?

>
> If you have issues with the posts of multiple people, the issue might not
> be on their eind.


I'm sure that is true, but what does it have to do with this thread?

--
Lew
 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      06-05-2013
In article
<(E-Mail Removed)>,
Haircuts Are Important <(E-Mail Removed)> wrote:

> The capability that I am trying to get is this. I have two
> tables with the right one being a lot larger than the left
> one. What I have been attempting to do is scroll the right
> table vertically and have the left table scroll vertically at
> the same time.


Summarizing some of my earlier suggestions on shared models and timers,
the sscce below illustrates how I would proceed. I've also used the
event dispatch thread and shown an alternate approach to scrolling.

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;

class ParallelTables {

private final DefaultTableModel modelA = initModel(1);
private JTable tableA = new JTable(modelA) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = super.getPreferredScrollableViewportSize();
return new Dimension(d.width / 2, d.height);
}
};
private final DefaultTableModel modelB = initModel(5);
private JTable tableB = new JTable(modelB);

private DefaultTableModel initModel(int n) {
DefaultTableModel model = new DefaultTableModel(100, n);
for (int row = 0; row < model.getRowCount(); row++) {
model.setValueAt(row, row, 0);
}
return model;
}

private void display() {
final JScrollPane scrollA = new JScrollPane(tableA);
JScrollPane scrollB = new JScrollPane(tableB);
scrollA.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_NEVER);
scrollA.getVerticalScrollBar().setModel(
scrollB.getVerticalScrollBar().getModel());
tableA.setSelectionModel(tableB.getSelectionModel( ));
JPanel panel = new JPanel(
new FlowLayout(FlowLayout.LEFT, 0, 0));
panel.add(scrollA);
panel.add(scrollB);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(panel);
f.pack();
f.setLocationByPlatform(true);
f.setVisible(true);

int last = modelA.getRowCount() - 1;
tableA.getSelectionModel().setSelectionInterval(la st, last);
tableA.scrollRectToVisible(
tableA.getCellRect(last, last, true));
Timer t = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
modelA.addRow(new Object[]{42});
modelB.addRow(new Object[]{42, 42, 42, 42, 42});
int last = modelA.getRowCount() - 1;
tableA.scrollRectToVisible(
tableA.getCellRect(last, last, true));
}
});
t.setInitialDelay(0);
t.start();
}

public static void main(String[] args) throws Exception {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new ParallelTables().display();
}
});
}
}

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
Joerg Meier
Guest
Posts: n/a
 
      06-05-2013
On Tue, 4 Jun 2013 19:48:57 -0700 (PDT), Lew wrote:

> Joerg Meier wrote:
>> Lew wrote:
>>> Haircuts Are Important wrote:
>>>> Lew wrote:
>>>>> > *Haircuts Are Important wrote:
>>>>> > > > For improved visual coherence, the tables can share a selection
>>>>> > > > model, much as you have done with the scrollbars'
>>>>> > > > BoundedRangeModel:
>>>>> ...


>>>>> What happened to all your posts?
>>>> I'm still listening.
>>> That's nice.
>>> What happened to all your posts?

>> If you have issues with the posts of multiple people, the issue might not
>> be on their eind.

> I'm sure that is true, but what does it have to do with this thread?


On this thread, you have addressed two different people and asked about
their posts, Haircuts and John Matthews. From the context, I'm now guessing
the first one was due to not having a post of Haircuts left to reply to ?

Either way, it does seem to be on 'your' end (Google) - the posts are still
visible on my news server, and nothing about them seems special or unusual.

Liebe Gruesse,
Joerg

--
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      06-05-2013
Joerg Meier wrote:
> Lew wrote:
> > Joerg Meier wrote:
> >> Lew wrote:
> >>> Haircuts Are Important wrote:
> >>>> Lew wrote:
> >>>>> > ´┐ŻHaircuts Are Important wrote:
> >>>>> > > > For improved visual coherence, the tables can share a selection
> >>>>> > > > model, much as you have done with the scrollbars'
> >>>>> > > > BoundedRangeModel:
> >>>>> ...

>
> >>>>> What happened to all your posts?

>
> >>>> I'm still listening.

>
> >>> That's nice.

>
> >>> What happened to all your posts?

>
> >> If you have issues with the posts of multiple people, the issue might not
> >> be on their eind.

>
> > I'm sure that is true, but what does it have to do with this thread?

>
> On this thread, you have addressed two different people and asked about
> their posts, Haircuts and John Matthews. From the context, I'm now guessing


Looking at the attributions, which your posts preserved, you can see that
both questions were addressed to the same person.

> the first one was due to not having a post of Haircuts left to reply to ?


It was due to every post of Haircuts' being marked "This message has been deleted."

Something to which John Matthews also alluded in response to your post.

> Either way, it does seem to be on 'your' end (Google) - the posts are still
> visible on my news server, and nothing about them seems special or unusual.


Thank you. That is helpful to know.

Still, for even GG to report that the messages have been deleted, someone
took an affirmative action to delete them. So I took the reasonable action
of asking the poster what happened, under the hypothesis that they initiated
the deletion. The answer I got was tangential at best, and completely
devoid of useful content, so I repeated the question - to the same person.

So I ask Haircut this: Did you in some fashion "delete" your posts?

--
Lew
 
Reply With Quote
 
Haircuts Are Important
Guest
Posts: n/a
 
      06-05-2013
On Jun 4, 11:04*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
> *Haircuts Are Important <(E-Mail Removed)> wrote:
>
> > The capability that I am trying to get is this. I have two
> > tables with the right one being a lot larger than the left
> > one. What I have been attempting to do is scroll the right
> > table vertically and have the left table scroll vertically at
> > the same time.

>
> Summarizing some of my earlier suggestions on shared models and timers,
> the sscce below illustrates how I would proceed. I've also used the
> event dispatch thread and shown an alternate approach to scrolling.
>
> import java.awt.Dimension;
> import java.awt.EventQueue;
> import java.awt.FlowLayout;
> import java.awt.event.ActionEvent;
> import java.awt.event.ActionListener;
> import javax.swing.JFrame;
> import javax.swing.JPanel;
> import javax.swing.JScrollPane;
> import javax.swing.JTable;
> import javax.swing.Timer;
> import javax.swing.table.DefaultTableModel;
>
> class ParallelTables {
>
> * * private final DefaultTableModel modelA = initModel(1);
> * * private JTable tableA = new JTable(modelA) {
> * * * * @Override
> * * * * public Dimension getPreferredScrollableViewportSize() {
> * * * * * * Dimension d = super.getPreferredScrollableViewportSize();
> * * * * * * return new Dimension(d.width / 2, d.height);
> * * * * }
> * * };
> * * private final DefaultTableModel modelB = initModel(5);
> * * private JTable tableB = new JTable(modelB);
>
> * * private DefaultTableModel initModel(int n) {
> * * * * DefaultTableModel model = new DefaultTableModel(100, n);
> * * * * for (int row = 0; row < model.getRowCount(); row++) {
> * * * * * * model.setValueAt(row, row, 0);
> * * * * }
> * * * * return model;
> * * }
>
> * * private void display() {
> * * * * final JScrollPane scrollA = new JScrollPane(tableA);
> * * * * JScrollPane scrollB = new JScrollPane(tableB);
> * * * * scrollA.setVerticalScrollBarPolicy(
> * * * * * * JScrollPane.VERTICAL_SCROLLBAR_NEVER);
> * * * * scrollA.getVerticalScrollBar().setModel(
> * * * * * * scrollB.getVerticalScrollBar().getModel());
> * * * * tableA.setSelectionModel(tableB.getSelectionModel( ));
> * * * * JPanel panel = new JPanel(
> * * * * * * new FlowLayout(FlowLayout.LEFT, 0, 0));
> * * * * panel.add(scrollA);
> * * * * panel.add(scrollB);
> * * * * JFrame f = new JFrame();
> * * * * f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> * * * * f.add(panel);
> * * * * f.pack();
> * * * * f.setLocationByPlatform(true);
> * * * * f.setVisible(true);
>
> * * * * int last = modelA.getRowCount() - 1;
> * * * * tableA.getSelectionModel().setSelectionInterval(la st, last);
> * * * * tableA.scrollRectToVisible(
> * * * * * * tableA.getCellRect(last, last, true));
> * * * * Timer t = new Timer(1000, new ActionListener() {
> * * * * * * @Override
> * * * * * * public void actionPerformed(ActionEvent e) {
> * * * * * * * * modelA.addRow(new Object[]{42});
> * * * * * * * * modelB.addRow(new Object[]{42, 42, 42, 42, 42});
> * * * * * * * * int last = modelA.getRowCount() - 1;
> * * * * * * * * tableA.scrollRectToVisible(
> * * * * * * * * * * tableA.getCellRect(last, last, true));
> * * * * * * }
> * * * * });
> * * * * t.setInitialDelay(0);
> * * * * t.start();
> * * }
>
> * * public static void main(String[] args) throws Exception {
> * * * * EventQueue.invokeLater(new Runnable() {
> * * * * * * @Override
> * * * * * * public void run() {
> * * * * * * * * new ParallelTables().display();
> * * * * * * }
> * * * * });
> * * }
>
> }
>


This appears to be useful, but I have a few improvements to ask about.

(1) The table automatically scrolls to one less than the number of
rows in the table. It does not scroll to the last row!

(2) When resizing the window, how do you get both tables to show more
rows. The tables show only about 25 rows and never the last row.

(3 When I, myself, do begin to add more code to this project where
should I be concerned about exceptions occurring. Will adding "try-
catch" pairs get me around all exceptions. What exceptions can I
ignore. When should I use a SwingWorker.


 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      06-05-2013
In article
<(E-Mail Removed)>,
Haircuts Are Important <(E-Mail Removed)> wrote:

> On Jun 4, 11:04┬*pm, "John B. Matthews" <(E-Mail Removed)> wrote:
> > In article
> > <(E-Mail Removed)>,
> > ┬*Haircuts Are Important <(E-Mail Removed)> wrote:
> >
> > > The capability that I am trying to get is this. I have two tables
> > > with the right one being a lot larger than the left one. What I
> > > have been attempting to do is scroll the right table vertically
> > > and have the left table scroll vertically at the same time.

> >
> > Summarizing some of my earlier suggestions on shared models and
> > timers, the sscce below illustrates how I would proceed. I've also
> > used the event dispatch thread and shown an alternate approach to
> > scrolling.
> >
> > [...]

>
> This appears to be useful, but I have a few improvements to ask about.
>
> (1) The table automatically scrolls to one less than the number of
> rows in the table. It does not scroll to the last row!
>
> (2) When resizing the window, how do you get both tables to show more
> rows. The tables show only about 25 rows and never the last row.


My example starts with 100 rows, numbered 0 .. 99; added rows are
numbered 42. I don't recall the numbering used in your examples.

Apropos to this, I would reiterate Lew's question about your now deleted
examples. As Joerg Meier helpfully observed, they can be retrieved from
one's NNTP server, but you might clarify your preference.

> (3 When I, myself, do begin to add more code to this project where
> should I be concerned about exceptions occurring. Will adding "try-
> catch" pairs get me around all exceptions. What exceptions can I
> ignore. When should I use a SwingWorker.


Without context, the short answers are these: don't swallow exceptions
and don't block the EDT.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      06-05-2013
John B. Matthews wrote:
> Apropos to this, I would reiterate Lew's question about your now deleted
> examples. As Joerg Meier helpfully observed, they can be retrieved from
> one's NNTP server, but you might clarify your preference.


I figure he just doesn't want to answer this question. He's ignored it at least thrice so far.

--
Lew
 
Reply With Quote
 
clusardi2k@aol.com
Guest
Posts: n/a
 
      06-05-2013
On Wednesday, June 5, 2013 4:02:04 PM UTC-4, John B. Matthews wrote:
> In article <(E-Mail Removed)>, Haircuts Are Important <(E-Mail Removed)> wrote: > On Jun 4, 11:04*pm, "John B. Matthews" <(E-Mail Removed)> wrote: > > In article > > <(E-Mail Removed)>, > > *Haircuts Are Important <(E-Mail Removed)> wrote: > > > > > The capability that I am trying to get is this. I have two tables > > > with the right one being a lot larger than the left one. What I > > > have been attempting to do is scroll the right table vertically > > > and have the left table scroll vertically at the same time. > > > > Summarizing some of my earlier suggestions onshared models and > > timers, the sscce below illustrates how I would proceed. I've also > > used the event dispatch thread and shown an alternate approach to > > scrolling. > > > > [...] > > This appears to be useful, but Ihave a few improvements to ask about. > > (1) The table automatically scrolls to one less than the number of > rows in the table. It does not scroll to the last row! > > (2) When resizing the window, how do you get both tables to show more > rows. The tables show only about 25 rows and never the last row. My example starts with 100 rows, numbered 0 .. 99; added rows are numbered 42. I don't recall the numbering used in your examples. Apropos to this, I would reiterate Lew's question about your now deleted examples. As Joerg Meier helpfully observed, they can be retrieved from one's NNTP server, but you might clarify your preference. > (3 When I, myself, do begin to add more code to this project where > should I be concerned about exceptions occurring. Will adding "try- > catch" pairs get me around all exceptions.What exceptions can I > ignore. When should I use a SwingWorker. Without context, the short answers are these: don't swallow exceptions and don't block the EDT. -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>


Thanks for your code

I think I can get the vertical scrolling to work by adding an extra row at the very top of the two tables. I'll then insert data into that empty row and create a new empty row each time after I add the data. So, the automaticvertical scrolling will never show the empty bottom row.

About only showing about 25 rows. I meant to say that the scrolling works. I do see all the rows created, but the project only shows 25 at a time. So,I see 0 through 25, then 1 through 26, then 2 through 27, ..., then n through n+25. So, I was wondering if it would be possible to be able to see more than 25 rows at a time apon a resize via a mouse drag.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      06-06-2013
(E-Mail Removed) wrote:
> John B. Matthews wrote:
> > In article <(E-Mail Removed)>, Haircuts Are Important <(E-Mail Removed)> wrote: > On Jun 4, 11:04*pm, "John B. Matthews" <(E-Mail Removed)> wrote: > > In article > > <(E-Mail Removed)>, > > *Haircuts Are Important <(E-Mail Removed)> wrote: > > > > > The capability that I am trying to get is this. I have two tables > > > with the right one being alot larger than the left one. What I > > > have been attempting to do is scroll the right table vertically > > > and have the left table scroll vertically at the same time. > > > > Summarizing some of my earlier suggestions on shared models and > > timers, the sscce below illustrates how I would proceed. I've also > > used the event dispatch thread and shown an alternate approach to > > scrolling. > > > > [...] > > This appears to be useful, butI have a few improvements to ask about. > > (1) The table automatically scrolls to one less than the number of > rows in the table. It does not scroll to the last row! > > (2) When resizing the window, how do you get both tables to show more > rows. The tables show only about 25 rows and never the last row. My example starts with 100 rows, numbered 0 .. 99; added rows arenumbered 42. I don't recall the numbering used in your examples. Apropos to this, I would reiterate Lew's question about your now deleted examples. As Joerg Meier helpfully observed, they can be retrieved from one's NNTP server, but you might clarify your preference. > (3 When I, myself, do begin to add more code to this project where > should I be concerned about exceptions occurring. Will adding "try- > catch" pairs get me around all exceptions. What exceptions can I > ignore. When should I use a SwingWorker. Withoutcontext, the short answers are these: don't swallow exceptions and don't block the EDT. -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>

>
> Thanks for your code
>
> I think I can get the vertical scrolling to work by adding an extra row at the very top of the two tables. I'll then insert data into that empty rowand create a new empty row each time after I add the data. So, the automatic vertical scrolling will never show the empty bottom row.
>
> About only showing about 25 rows. I meant to say that the scrolling works.. I do see all the rows created, but the project only shows 25 at a time. So, I see 0 through 25, then 1 through 26, then 2 through 27, ..., then n through n+25. So, I was wondering if it would be possible to be able to see more than 25 rows at a time apon a resize via a mouse drag.


Aaand ...

He ignores the question again.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
freeze column headings Seth Williams ASP .Net 2 10-17-2008 04:57 PM
freeze string fails to freeze ??? jwaala.amplify@gmail.com Ruby 5 03-15-2007 11:29 PM
Sending an E-mail (Code Included with post) Michael Perl 2 09-15-2004 02:08 PM
Freeze column(s) in a Datagrid =?Utf-8?B?QmVu?= ASP .Net 1 06-05-2004 06:35 PM
Re: help with insert/updating date variables in table code included ASP .Net 1 12-14-2003 11:28 PM



Advertisments