Code Included: Freeze column

  • Thread starter Haircuts Are Important
  • Start date
H

Haircuts Are Important

I attempted to modify 2 different projects on the Internet.

As you know, I have been trying to duplicate the Excel spreadsheet
freeze column capability while maintaining scrollability (vertical
across the 2 tables).

First, my problem with a modified version (added dynamically adding
rows to the 2 tables using "insert") of the code at
http://www.java2s.com/Code/Java/Swing-Components/FixedTableColumnExample.htm
produced code where the 2 tables wouldn't do exactly what I wanted.
Basically, I have been unable to get the the 2 tables to scroll
vertically together etc.

Second below, if I change the dimension of either JScrollPane it
changes the second one. So, the result is I either get a large left
JScrollPane or a small right JScrollPane.

I'd also like to remove any spacing between these 2 tables.

Third, I also tried to put each table into a separate JPanel and put
all this into a JScrollPane, but it (appeared to) yield the same
results as the second thing I tried.

What are the details to accomplish this.

Thanks,

class ParallelTables {
static JScrollPane createTableA() {
DefaultTableModel model = new DefaultTableModel(100, 1);
for (int row=model.getRowCount(); --row>=0;) {
model.setValueAt(row, row, 0);
}
JTable table = new JTable(model);
return new JScrollPane(table);
}

static JScrollPane createTableB() {
DefaultTableModel model = new DefaultTableModel(100, 5);
for (int row=model.getRowCount(); --row>=0;) {
model.setValueAt(row, row, 0);
}
JTable table = new JTable(model);
return new JScrollPane(table);
}

public static void main(String[] args) throws Exception {

JScrollPane scrollerA = createTableA();
JScrollPane scrollerB = createTableB();
scrollerA.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_NEVER);
// the following statement binds the same BoundedRangeModel to
both vertical scrollbars.
scrollerA.getVerticalScrollBar().setModel(
scrollerB.getVerticalScrollBar().getModel());
JPanel panel = new JPanel();
panel.add(scrollerA);
panel.add(scrollerB);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}
 
J

John B. Matthews

Haircuts Are Important said:
Basically, I have been unable to get the the 2 tables to scroll
vertically together etc.

Your example using a shared model seems to do exactly this.
Second below, if I change the dimension of either JScrollPane it
changes the second one. So, the result is I either get a large left
JScrollPane or a small right JScrollPane.

JTable implements Scrollable; you can override the method
getPreferredScrollableViewportSize() to make table A narrower:

final JTable table = new JTable(model) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension d = super.getPreferredScrollableViewportSize();
return new Dimension(d.width / 2, d.height);
}
};
I'd also like to remove any spacing between these 2 tables.

The space comes from the default FlowLayout; try this:

JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
Third, I also tried to put each table into a separate JPanel and put
all this into a JScrollPane, but it (appeared to) yield the same
results as the second thing I tried.

I don't understand.
 
C

clusardi2k

Your example using a shared model seems to do exactly this.

Yes, but I have to throw away that model in favor of another one because I have to continually add rows to the tables as the project runs. The shared model in the example doesn't allow me to use the "insert" method which is available in another model.

I.E.: The shared model example populates the tables all at once and not sporadically!

How can I add new rows to the two tables of the shared model example every few minutes and not all at once.

Thanks
 
J

John B. Matthews

Yes, but I have to throw away that model in favor of another one
because I have to continually add rows to the tables as the project
runs. The shared model in the example doesn't allow me to use the
"insert" method which is available in another model.

I.E.: The shared model example populates the tables all at once and
not sporadically!

How can I add new rows to the two tables of the shared model example
every few minutes and not all at once.

Given two row-conformal models, I'd use javax.swing.Timer:

Timer t = new Timer(1000, new ActionListener() { // ~ 1 Hz
@Override
public void actionPerformed(ActionEvent e) {
modelA.addRow(new Object[]{42});
modelB.addRow(new Object[]{42, 42, 42, 42, 42});
JScrollBar vertical = scrollerA.getVerticalScrollBar();
vertical.setValue(vertical.getMaximum());
}
});
t.start();

<http://stackoverflow.com/a/5150437/230513>
 
H

Haircuts Are Important

I have modified the code at the below link. Everything seems to work
except horizontal scrolling across the two tables:
http://www.java2s.com/Code/Java/Swing-Components/FixedTableColumnExample.htm.

Again, at run-time (via the routine attached to the timer) the project
will add different data to the bottom of each table. The bottom row is
highlighted in each table. The frozen columns are doing what they're
suppose to.

But, when I use the scrollbar on the right table, the left table does
not move.

Here is a non-compilable summary of the resulting code. (The timer
class is not there) Can you get the left table to match the scrolling
on the right table?

Thanks

package test;

class Test extends JFrame{
public static FixedModel fixedModel;//FixedModel extends
AbstractTableModel see below
public static ModelWithScrollbar mainModel;//ModelWithScrollbar
extends AbstractTableModel see below
public static JTable fixedTable; //Has the frozen columns
public static JTable scrollTable; //Has a visible scrollbar

public Test ()[

t.startTimer();

this.setVisible(true);
this.setTitle ("An example");

fixedModel = new FixedModel ();

fixedTable = new JTable (fixedModel){
@Override
public void valueChanged(ListSelectionEvent e){
super.valueChanged(e);
checkSelection(true);
}
};

mainModel = new ModelWithScrollbar();

scrollTable = new JTable (mainModel){
@Override
public void valueChanged(ListSelectionEvent e){
super.valueChanged(e);
checkSelection(false);
}
};

Dimension dimensin = new Dimensin(0,0);
fixedTable.getTableHeader().setPreferredSize(dimension);
scrollTable.getTableHeader().setPreferredSize(dimension);

fixedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

fixedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

scrollTable.setFocusable(false);

JScrollPane jScrollPane1 = new JScrollPane(scrollTable);

JViewport viewport = new JViewport();
viewport.setView(fixedTable);
viewport.setPreferredSize(fixedTable,getPreferredSize());
jScrollPane1.setRowHeaderView(viewport);

jScrollPane1.setCorner(JScrollPane.UPPER_LEFT_CORNER,fixedTable.getTableHeader());
getContentPane().add(jScrollPane1,BorderLayout.CENTER);
}

//Indirectly called via Timer t
public static void add_Rows_To_Tables (){

String[] tmp1 = new String [3];
String[] tmp2 = new String [90];

//...
fixedModel.addRow(Arrays.asList(tmp1));
mainModel.addRow(Arrays.asList(tmp2));

fixedTable.getSelectionMode().setSelectionInterval(
fixedTable.getRowCount () - 1,
fixedTable.getRowCount () - 1);

scrollTable.getSelectionMode().setSelectionInterval(
scrollTable.getRowCount () - 1,
scrollTable.getRowCount () - 1);

fixedTable.scrollRectToVisible(
new Rectangle (
fixedTable.getCellRect(
fixedTable.getRowCount() - 1,
0,
true)));

scrollTable.scrollRectToVisible(
new Rectangle (
scrollTable.getCellRect(
scrollTable.getRowCount() - 1,
0,
true)));
}

private void checkSelection(boolean isFixedTable){
int fixedSelectedIndex = fixedTaboe.geSelectedRow();
int selectedIndex = scrollTable.getSelectedRow();

if (fixedSelectedIndex != selectedIndex){
if (isFixedTable){

scrollTable.setRowSelectionInterval(fixedSelectedIndex,fixedSelectedIndex);
} else {

fixedTable.setRowSelectionInterval(selectedIndex,selectedIndex);
}
}
}

public static main (String[] args){
Test frame = new Test ();

frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
frame.setVisible (true);
}
}




public class FixedModel extends AbstractTableModel{
static public List<String> columnNames = new ArrayList();
static public List<List> data = new ArrayList();

{//annonymous class
for (int i = 0;i < 3; i++){
columnNames.add(" ");
}
}

public void addRow(List rowData){
data.add(rowData);
fireTableRowsInserted(data.size() - 1,data.size() - 1);
}

public int getColumnCount() {
return columnNames.size();
}

public int getRowCount() {
return data.size();
}

@Override
public String getColumnName(int col) {
try {
return columnNames.get(col);
} catch (Exception exception) {
return null;
}
}

public Object getValueAt(int row, int col) {
return data.get(row).get(col);
}

public boolean isCellEditable(int row, int col) {
return false;
}

public Class getColumnClass(int c) {
return getValueAt(0,c).getClass();
}
};





public class ModelWithScrollbar extends AbstractTableModel{
static public List<String> columnNames = new ArrayList();
static public List<List> data = new ArrayList();

{//annonymous class
for (int i = 0;i < 90; i++){
columnNames.add(" ");
}
}

public void addRow(List rowData){
data.add(rowData);
fireTableRowsInserted(data.size() - 1,data.size() - 1);
}

public int getColumnCount() {
return columnNames.size();
}

public int getRowCount() {
return data.size();
}

@Override
public String getColumnName(int col) {
try {
return columnNames.get(col);
} catch (Exception exception) {
return null;
}
}

public Object getValueAt(int row, int col) {
return data.get(row).get(col);
}

public boolean isCellEditable(int row, int col) {
return false;
}

public Class getColumnClass(int c) {
try {
return getValueAt(0,c).getClass();
}
catch (Exceptin exception) {// MAY LEAD TO ERROR
return this.getClass();
}
}
};
 
H

Haircuts Are Important

I have modified the code at the below link. Everything seems to work
except horizontal scrolling across the two tables:
http://www.java2s.com/Code/Java/Swing-Components/FixedTableColumnExam....

Again, at run-time (via the routine attached to the timer) the
project
will add different data to the bottom of each table. The bottom row
is
highlighted in each table. The frozen columns are doing what they're
suppose to.


But, when I use the scrollbar on the right table, the left table does
not move.


Here is a non-compilable summary of the resulting code. (The timer
class is not there) Can you get the left table to match the scrolling
on the right table?


Thanks


package test;

class Test extends JFrame{
public static FixedModel fixedModel;//FixedModel extends
AbstractTableModel see below
public static ModelWithScrollbar mainModel;//ModelWithScrollbar
extends AbstractTableModel see below
public static JTable fixedTable; //Has the frozen columns
public static JTable scrollTable; //Has a visible scrollbar


public Test (){

t.startTimer();

this.setVisible(true);
this.setTitle ("An example");

fixedModel = new FixedModel ();

fixedTable = new JTable (fixedModel){
@Override
public void valueChanged(ListSelectionEvent e){
super.valueChanged(e);
checkSelection(true);
}
};

mainModel = new ModelWithScrollbar();

scrollTable = new JTable (mainModel){
@Override
public void valueChanged(ListSelectionEvent e){
super.valueChanged(e);
checkSelection(false);
}
};


Dimension dimension = new Dimension(0,0);
fixedTable.getTableHeader().setPreferredSize(dimension);
scrollTable.getTableHeader().setPreferredSize(dimension);

fixedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

fixedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

scrollTable.setFocusable(false);

JScrollPane jScrollPane1 = new JScrollPane(scrollTable);

JViewport viewport = new JViewport();
viewport.setView(fixedTable);
viewport.setPreferredSize(fixedTable,getPreferredSize());
jScrollPane1.setRowHeaderView(viewport);


jScrollPane1.setCorner(JScrollPane.UPPER_LEFT_CORNER,fixedTable.getTableHea­
der());
getContentPane().add(jScrollPane1,BorderLayout.CENTER);


}


//Indirectly called via Timer t
public static void add_Rows_To_Tables (){

String[] tmp1 = new String [3];
String[] tmp2 = new String [90];

//...
fixedModel.addRow(Arrays.asList(tmp1));
mainModel.addRow(Arrays.asList(tmp2));

fixedTable.getSelectionMode().setSelectionInterval(
fixedTable.getRowCount () - 1,
fixedTable.getRowCount () - 1);

scrollTable.getSelectionMode().setSelectionInterval(
scrollTable.getRowCount () - 1,
scrollTable.getRowCount () - 1);

fixedTable.scrollRectToVisible(
new Rectangle (
fixedTable.getCellRect(
fixedTable.getRowCount() - 1,
0,
true)));


scrollTable.scrollRectToVisible(
new Rectangle (
scrollTable.getCellRect(
scrollTable.getRowCount() - 1,
0,
true)));
}


private void checkSelection(boolean isFixedTable){
int fixedSelectedIndex = fixedTable.geSelectedRow();
int selectedIndex = scrollTable.getSelectedRow();

if (fixedSelectedIndex != selectedIndex){
if (isFixedTable){

scrollTable.setRowSelectionInterval(fixedSelectedIndex,fixedSelectedIndex);
} else {

fixedTable.setRowSelectionInterval(selectedIndex,selectedIndex);
}
}
}


public static main (String[] args){
Test frame = new Test ();

frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
frame.setVisible (true);
}
}


public class FixedModel extends AbstractTableModel{
static public List<String> columnNames = new ArrayList();
static public List<List> data = new ArrayList();

{//annonymous class
for (int i = 0;i < 3; i++){
columnNames.add(" ");
}
}


public void addRow(List rowData){
data.add(rowData);
fireTableRowsInserted(data.size() - 1,data.size() - 1);
}


public int getColumnCount() {
return columnNames.size();
}

public int getRowCount() {
return data.size();
}

@Override
public String getColumnName(int col) {
try {
return columnNames.get(col);
} catch (Exception exception) {
return null;
}
}

public Object getValueAt(int row, int col) {
return data.get(row).get(col);
}


public boolean isCellEditable(int row, int col) {
return false;
}

public Class getColumnClass(int c) {
return getValueAt(0,c).getClass();
}
};


public class ModelWithScrollbar extends AbstractTableModel{
static public List<String> columnNames = new ArrayList();
static public List<List> data = new ArrayList();

{//annonymous class
for (int i = 0;i < 90; i++){
columnNames.add(" ");
}
}


public void addRow(List rowData){
data.add(rowData);
fireTableRowsInserted(data.size() - 1,data.size() - 1);
}

public int getColumnCount() {
return columnNames.size();
}

public int getRowCount() {
return data.size();
}

@Override
public String getColumnName(int col) {
try {
return columnNames.get(col);
} catch (Exception exception) {
return null;
}
}

public Object getValueAt(int row, int col) {
return data.get(row).get(col);
}

public boolean isCellEditable(int row, int col) {
return false;
}

public Class getColumnClass(int c) {
try {
return getValueAt(0,c).getClass();
}
catch (Exception exception) {// MAY LEAD TO ERROR
return this.getClass();
}
}
};
 
L

Lew

Haircuts said:
public class ModelWithScrollbar extends AbstractTableModel{
static public List<String> columnNames = new ArrayList();
static public List<List> data = new ArrayList();

{//annonymous [sic] class

There is no anonymous class here. Why the comment?
 
H

Haircuts Are Important

Haircuts said:
public class ModelWithScrollbar extends AbstractTableModel{
   static public List<String> columnNames = new ArrayList();
   static public List<List> data = new ArrayList();
   {//annonymous [sic] class

There is no anonymous class here. Why the comment?
       for (int i = 0;i < 90; i++){
          columnNames.add(" ");
       }
   }

If it's not an annonymous class what is it called.

Thanks,
 
H

Haircuts Are Important

I have modified the code at the below link. Everything seems to work

Let me try to clarify the problem, when I use the vertical
scrollbar on the right table, the left table does not move.

Any assistance would be greatly appreciated!

Thanks,
 
L

Lew

Haircuts said:
Lew said:
Haircuts said:
public class ModelWithScrollbar extends AbstractTableModel{
   static public List<String> columnNames = new ArrayList();
   static public List<List> data = new ArrayList();
   {//annonymous [sic] class

There is no anonymous class here. Why the comment?
       for (int i = 0;i < 90; i++){
          columnNames.add(" ");
       }
   }

If it's not an annonymous [sic] class what is it called.

If by "it" you mean the block with the 'for' loop in it, that is an initializer.
It is not any kind of class, let alone an anonymous one.

It is also a bug. You are using an instance initializer to initialize a static
construct.

That means that every instance of that class, should there ever be more
than one, will add another 90 items to the 'columnNames' collection, resulting
in a total size in excess of 90.

It is usually a bad idea to initialize a static structure in an instance context.

Study the following terms to be clear on these matters: "initializer" (both"static initializer"
and "instance initializer"), "class", "anonymous class", "static member".
 
H

Haircuts Are Important

Haircuts said:
Lew said:
Haircuts Are Important wrote:
public class ModelWithScrollbar extends AbstractTableModel{
   static public List<String> columnNames = new ArrayList();
   static public List<List> data = new ArrayList();
   {//annonymous [sic] class
There is no anonymous class here. Why the comment?
       for (int i = 0;i < 90; i++){
          columnNames.add(" ");
       }
   }
If it's not an annonymous [sic] class what is it called.

If by "it" you mean the block with the 'for' loop in it, that is an initializer.
It is not any kind of class, let alone an anonymous one.

It is also a bug. You are using an instance initializer to initialize a static
construct.

That means that every instance of that class, should there ever be more
than one, will add another 90 items to the 'columnNames' collection, resulting
in a total size in excess of 90.

It is usually a bad idea to initialize a static structure in an instance context.

Study the following terms to be clear on these matters: "initializer" (both "static initializer"
and "instance initializer"), "class", "anonymous class", "static member".

Thanks,
 
J

John B. Matthews

Haircuts Are Important said:
Everything seems to work except horizontal scrolling
across the two tables

You can tinker with setAutoResizeMode(); but absent some reason to
the contrary, I usually rely on the default.

For improved visual coherence, the tables can share a selection
model, much as you have done with the scrollbars' BoundedRangeModel:

tableA.setSelectionModel(tableB.getSelectionModel());
 
H

Haircuts Are Important

I'm lost here, can you give me more ideas? Problem: Both horizontal
and vertical scrolling works on the right table. But, vertical
scrolling on the right table does not scroll the left table!

You can tinker with setAutoResizeMode(); but absent some reason to
the contrary, I usually rely on the default.


Horizontal scrolling is working on the right table, so I don't think I
should be modifying setAutoResizeMode().

For improved visual coherence, the tables can share a selection
model, much as you have done with the scrollbars' BoundedRangeModel:

tableA.setSelectionModel(tableB.getSelectionModel());


Scrolling the right table vertically does not affect the row that is
highlighted.
So applying your idea via the below code is useless!

SharedClass implements ListselectionListener {
public void valueChanged (ListSelectionEvent evt){
int index = evt.getFirstIndex();
System.out.println ("Row = " + index);
}
}

listSelectionModel listSelectionModel = scrollTable.getSelectionModel
();
listSelectionModel.addListSelectionListener(new SharedClass());
scrollTable.setSelectionModel(listSelectionModel);
fixedModel.setSelectionModel (scrollTable.getSelectionModel());



//ORIGINAL CODE BELOW
package test;

public class ATimer {
public sttic void ATimer (){}
public static void startTimer(){
Timer timer;
timer = new Timer ();
timer.schedule (new TheData(),0,5000);
}
}

public class TheData extends TimerTask{//REALLY UNUSED CLASS
public void run(){//Data broken up to send to tables separately
//...
}
}

class Test extends JFrame{
public static FixedModel fixedModel;
public static ModelWithScrollbar mainModel;
public static JTable fixedTable;
public static JTable scrollTable;

public Test (){

ATimer.startTimer(); // Details omitted

this.setVisible(true);
this.setTitle ("An example");

fixedModel = new FixedModel ();

fixedTable = new JTable (fixedModel){
@Override
public void valueChanged(ListSelectionEvent e){
super.valueChanged(e);
checkSelection(true);
}
};

mainModel = new ModelWithScrollbar();

scrollTable = new JTable (mainModel){
@Override
public void valueChanged(ListSelectionEvent e){
super.valueChanged(e);
checkSelection(false);
}
};

Dimension dimension = new Dimension(0,0);
fixedTable.getTableHeader().setPreferredSize(dimension);
scrollTable.getTableHeader().setPreferredSize(dimension);

fixedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

fixedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

scrollTable.setFocusable(false);

JScrollPane jScrollPane1 = new JScrollPane(scrollTable);

JViewport viewport = new JViewport();
viewport.setView(fixedTable);
viewport.setPreferredSize(fixedTable,getPreferredSize());
jScrollPane1.setRowHeaderView(viewport);

jScrollPane1.setCorner(JScrollPane.UPPER_LEFT_CORNER,
fixedTable.getTableHea­­der());
getContentPane().add(jScrollPane1,BorderLayout.CENTER);
}

//Indirectly called via Timer t
public static void add_Rows_To_Tables (){

String[] tmp1 = new String [1]; //A, B, C, D, E ,F etc
String[] tmp2 = new String [10]; //

//...
fixedModel.addRow(Arrays.asList(tmp1));
mainModel.addRow(Arrays.asList(tmp2));

fixedTable.getSelectionMode().setSelectionInterval(
fixedTable.getRowCount () - 1,
fixedTable.getRowCount () - 1);

scrollTable.getSelectionMode().setSelectionInterval(
scrollTable.getRowCount () - 1,
scrollTable.getRowCount () - 1);

fixedTable.scrollRectToVisible(
new Rectangle (
fixedTable.getCellRect(
fixedTable.getRowCount() - 1,
0,
true)));

scrollTable.scrollRectToVisible(
new Rectangle (
scrollTable.getCellRect(
scrollTable.getRowCount() - 1,
0,
true)));
}

private void checkSelection(boolean isFixedTable){
int fixedSelectedIndex = fixedTable.geSelectedRow();
int selectedIndex = scrollTable.getSelectedRow();

if (fixedSelectedIndex != selectedIndex){
if (isFixedTable){


scrollTable.setRowSelectionInterval(fixedSelectedIndex,fixedSelectedIndex);
} else {

fixedTable.setRowSelectionInterval(selectedIndex,selectedIndex);
}
}
}

public static main (String[] args){
Test frame = new Test ();

frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
frame.setVisible (true);
}
}

public class FixedModel extends AbstractTableModel{
static public List<String> columnNames = new ArrayList();
static public List<List> data = new ArrayList();

{
for (int i = 0;i < 1; i++){
columnNames.add(" ");
}
}

public void addRow(List rowData){
data.add(rowData);
fireTableRowsInserted(data.size() - 1,data.size() - 1);
}

public int getColumnCount() {
return columnNames.size();
}

public int getRowCount() {
return data.size();
}

@Override
public String getColumnName(int col) {
try {
return columnNames.get(col);
} catch (Exception exception) {
return null;
}
}

public Object getValueAt(int row, int col) {
return data.get(row).get(col);
}

public boolean isCellEditable(int row, int col) {
return false;
}

public Class getColumnClass(int c) {
return getValueAt(0,c).getClass();
}

};


public class ModelWithScrollbar extends AbstractTableModel{
static public List<String> columnNames = new ArrayList();
static public List<List> data = new ArrayList();

{
for (int i = 0;i < 10; i++){
columnNames.add(" ");
}
}

public void addRow(List rowData){
data.add(rowData);
fireTableRowsInserted(data.size() - 1,data.size() - 1);
}

public int getColumnCount() {
return columnNames.size();
}

public int getRowCount() {
return data.size();
}

@Override
public String getColumnName(int col) {
try {
return columnNames.get(col);
} catch (Exception exception) {
return null;
}
}

public Object getValueAt(int row, int col) {
return data.get(row).get(col);
}

public boolean isCellEditable(int row, int col) {
return false;
}

public Class getColumnClass(int c) {
try {
return getValueAt(0,c).getClass();
}
catch (Exception exception) {// MAY LEAD TO ERROR
return this.getClass();
}
}
};
 
H

Haircuts Are Important

Per a definitoin for JViewport, do you think that my class
ModelWithScrollbar and class FixedModel should be sharing the exact
same members "data" and "columnNames" instead of having two pairs.

Thank you,
 
J

John B. Matthews

Haircuts Are Important said:
Scrolling the right table vertically does not affect the row that is
highlighted. So applying your idea via the below code is useless!

I mistakenly thought you wanted to synchronize vertical scrolling
between the two tables. I don't use Excel enough to understand its
"freeze column capability."
 
H

Haircuts Are Important

I mistakenly thought you wanted to synchronize vertical scrolling
between the two tables. I don't use Excel enough to understand its
"freeze column capability."

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.

I already have the "freeze" column capability working in the code
above.

I have not modified the code that I have recently posted.

Thanks for any help,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top