Invisible JScrollPane?
I have a JList matched up with a JTextArea. Inside the JList I want it to list numbers corresponding to the line in the JTextArea. I have the JList's and JTextArea's JScrollPanes synched up. But, I only want the JTextArea's JScrollPane to show up. Is it possible to have the JList's JScrollPane be invisible but because it is synched up with the JTextArea's JScrollPane still scroll through the JList? If you do not know what I mean or want more of my code, let me know.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
publicclass cfmCodeCounter1_1extends JFrame
{
private JLabel lblEnter;
private JTextArea input, output;
private JList row;
private JButton parse, clear, exit;
private JScrollPane scroller, scroller2, scroller3;
private Container c;
private Vector <String> rowVec;
privateboolean threadflag =false;// Used so only one thread for the CaretListener runs at one time
private cfmCodeCounter1_1()
{
try
{
this.setTitle("ColdFusion Parser - NGIT");
// Vector
rowVec =new Vector<String>();
// Display Label
lblEnter =new JLabel("Enter Code Below: ");
lblEnter.setVisible(true);
// JTextAreas
input =new JTextArea(10, 30);// (rows, columns)
input.setEditable(true);
scroller =new JScrollPane(input);
input.requestFocus();
output =new JTextArea(5, 19);// (rows, columns)
output.setEditable(false);
scroller2 =new JScrollPane(output);
output.requestFocus();
// Selectable List
row =new JList(rowVec);
row.setVisibleRowCount(10);
row.setFixedCellWidth(50);
row.setFixedCellHeight((input.getPreferredSize().height/10));
scroller3 =new JScrollPane(row);
// Set up scroller and scroller3
scroller.getVerticalScrollBar().setModel(scroller3.getVerticalScrollBar().getModel());
// Set up listener for input and row
TextHandler txthandle =new TextHandler();
input.addCaretListener(txthandle);
// Button
parse =new JButton("Parse Code");
clear =new JButton("Clear");
exit =new JButton("Exit");
// Set Layout
c = getContentPane();
SpringLayout layout =new SpringLayout();
c.setLayout(layout);
c.add(lblEnter);
c.add(scroller3);
c.add(scroller);
c.add(scroller2);
c.add(parse);
c.add(clear);
c.add(exit);
// Place lblEnter
layout.putConstraint(SpringLayout.WEST, lblEnter,
10,
SpringLayout.WEST, c);
layout.putConstraint(SpringLayout.NORTH, lblEnter,
10,
SpringLayout.NORTH, c);
// Place scroller3 aka row
layout.putConstraint(SpringLayout.WEST, scroller3,
10,
SpringLayout.WEST, c);
layout.putConstraint(SpringLayout.NORTH, scroller3,
5,
SpringLayout.SOUTH, lblEnter);
// Place scroller aka input
layout.putConstraint(SpringLayout.WEST, scroller,
-1,
SpringLayout.EAST, scroller3);
layout.putConstraint(SpringLayout.NORTH, scroller,
0,
SpringLayout.NORTH, scroller3);
// Place scroller2 aka output
layout.putConstraint(SpringLayout.WEST, scroller2,
5,
SpringLayout.EAST, scroller);
layout.putConstraint(SpringLayout.NORTH, scroller2,
0,
SpringLayout.NORTH, scroller);
// Place parse
layout.putConstraint(SpringLayout.WEST, parse,
10,
SpringLayout.WEST, c);
layout.putConstraint(SpringLayout.NORTH, parse,
5,
SpringLayout.SOUTH, scroller);
// Place clear
layout.putConstraint(SpringLayout.WEST, clear,
5,
SpringLayout.EAST, parse);
layout.putConstraint(SpringLayout.NORTH, clear,
0,
SpringLayout.NORTH, parse);
// Place exit
layout.putConstraint(SpringLayout.WEST, exit,
5,
SpringLayout.EAST, clear);
layout.putConstraint(SpringLayout.NORTH, exit,
0,
SpringLayout.NORTH, clear);
// Button Event Handler
ButtonHandler handler =new ButtonHandler();
parse.addActionListener(handler);
clear.addActionListener(handler);
exit.addActionListener(handler);
this.addWindowListener(new WindowAdapter()
{
publicvoid windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
setSize(650, 300);
setVisible(true);
}
catch(Exception e)
{
e.printStackTrace();
JOptionPane.showMessageDialog(null,"General Error: See Command Line.","ERROR - NGIT", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
privateclass TextHandlerimplements Runnable, CaretListener
{
publicvoid caretUpdate(CaretEvent e)
{
if (!threadflag)
{
threadflag =true;
Thread txtThread =new Thread(this);
txtThread.start();
}
}
publicvoid run()
{
rowVec.removeAllElements();
for (int i = 1; i <= input.getLineCount(); i++)
{
rowVec.add("" + i);
}
row.setListData(rowVec);
threadflag =false;
// Find current row of cursor
int numrows = 1;
char[] chararr = input.getText().toCharArray();
int caretPos = input.getCaretPosition();
for (int i = (caretPos-1); i >= 0; i--)
{
if (chararr[i] =='\n')
{
numrows++;
}
}
row.setSelectedIndex((numrows-1));
row.ensureIndexIsVisible((numrows-1));
}
}
//Code Continues

