aJTable
に aを追加JPanel
し、それをJPanel
aに追加すると、それがフォーカスJScrollPane
を得るたびJTable
に、スクロール ペインが自動的に一番下までスクロールします。これは悪いことです。
このようにする理由はたくさんあるので、この自動スクロールを止めるための何らかの解決策を期待しています。
ああ、これがキッカーです...アプリを実行しているときにのみ発生するようJNLP/WebStart
で、Eclipseでは実行されないため、さらにイライラします。
JLNP
以下は、 から起動し、テキスト フィールドをクリックし、表をクリックすると、自動的に一番下までスクロールする簡単な例です。
import java.awt.*;
import javax.swing.*;
public class ScrollDemo extends JPanel{
private static final long serialVersionUID = 1L;
public ScrollDemo()
{
this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
JTable table = new JTable(100,6);
this.add(new JTextField());
JPanel panel = new JPanel();
panel.add(table);
JScrollPane scroll = new JScrollPane(panel);
this.add(scroll);
}
/**
* Create the GUI and show it. For thread safety, this method should be
* invoked from the event-dispatching thread.
*/
private static void createAndShowGUI() {
// Create and set up the window.
JFrame frame = new JFrame("ScrollDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and set up the content pane.
JComponent newContentPane = new ScrollDemo();
newContentPane.setOpaque(true); // content panes must be opaque
frame.setContentPane(newContentPane);
frame.setPreferredSize(new Dimension(500, 500));
// Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
// Schedule a job for the event-dispatching thread:
// creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}