当滚动超过内容的50%时,将新数据添加到JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
中,但是问题是,在将滚动与内容一起移动到顶部之后,如何保存位置并滚动?更改了从底部开始的表的显示内容
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class Foo {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> createGui());
}
public static void createGui() {
Integer[][] rowData = { { 1, 2 }, { 3, 4 } };
String[] columnNames = { "A", "B" };
JTable table = new JTable(rowData, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
int condition = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
// int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
// int condition = JComponent.WHEN_FOCUSED;
InputMap inputMap = table.getInputMap(condition);
ActionMap actionMap = table.getActionMap();
KeyStroke saveKeystroke = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK);
KeyStroke pasteKeystroke = KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK);
String pasteKey = (String) inputMap.get(pasteKeystroke);
System.out.println(pasteKey);
inputMap.put(saveKeystroke, saveKeystroke.toString());
inputMap.put(pasteKeystroke, pasteKeystroke.toString());
actionMap.put(saveKeystroke.toString(), new MyAction("Save Action"));
actionMap.put(pasteKeystroke.toString(), new MyAction("Paste Action"));
JFrame frame = new JFrame("Foo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(scrollPane);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
@SuppressWarnings("serial")
class MyAction extends AbstractAction {
private String text;
public MyAction(String text) {
this.text = text;
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(text);
}
}
该怎么做,将添加新数据,并将滚动数据的内容保留在原处(例如电报)
已经尝试过,但是没有转移
tableview
答案 0 :(得分:0)
为什么您可以尝试?
app.on('ready', function () {
// Create new window
mainWindow = new BrowserWindow({webPreferences: {
nodeIntegration: false
}});
// Load php index into window
mainWindow.setTitle('Test');
mainWindow.loadURL('http://www.url.com/index.php');
//mainWindow.webContents.openDevTools();
mainWindow.setMenu(null);
mainWindow.on('closed', () => {
mainWindow.loadURL('https://www.url.com/logout.php?logout=true');
mainWindow = null;
app.quit();
});
});
您可以使用表中加载的索引来添加更多值。
在加载单元格时,您可以调用该函数以向表视图添加更多数据,因此,如果在加载5个单元格时以10个值开头的数据在数组temp中添加了10个itens,那么该数组现在具有20个值,当表格加载索引为10时,您会调用更多iten。