gpt4 book ai didi

java - 无法从 jtable 中删除重复项。

转载 作者:行者123 更新时间:2023-11-29 23:09:54 26 4
gpt4 key购买 nike

我在 mysql 中有两个不同的表,我想将它们合并到一个表中。我合并了,但有副本,我无法删除它们。我首先使用哈希集,它适用于第一个表,但是当我组合第二个表时它消失了。现在我不想写一些长计算,因为项目太大并且它与数据库一起工作,所以它会运行得很慢。

enter image description here

public final class IsdenCixanlar extends javax.swing.JFrame {

public final String[][] array;
public final List<Pojo> list;
public int index = 0;
public String ad = null;

public JTable autoResizeColWidth(JTable table, TableModel model) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setModel(model);
int margin = 5;
for (int i = 0; i < table.getColumnCount(); i++) {
int vColIndex = i;
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(vColIndex);
int width;
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null) {
renderer = table.getTableHeader().getDefaultRenderer();
}
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
for (int r = 0; r < table.getRowCount(); r++) {
renderer = table.getCellRenderer(r, vColIndex);
comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false,
r, vColIndex);
width = Math.max(width, comp.getPreferredSize().width);
}
width += 2 * margin;
col.setPreferredWidth(width);
}
((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(
SwingConstants.LEFT);
table.getTableHeader().setReorderingAllowed(false);
return table;
}

public IsdenCixanlar() {
initComponents();
//setTitle("İşdən çıxanlar");
setLocationRelativeTo(null);
list = new ArrayList<>(DBO.salary());
for (Iterator<Pojo> itr = list.iterator(); itr.hasNext();) {
Pojo element = itr.next();
if (element.getIsleyir() == 0) {
itr.remove();
}
if ("null".equals(element.getAd())) {
itr.remove();
}
if ("".equals(element.getAd())) {
itr.remove();
}
}
array = new String[list.size()][2];
list.stream().forEach((list1) -> {
if (ad == null ? list1.getAd() != null : !ad.equals(list1.getAd())) {
array[index][0] = list1.getAd();
array[index][1] = DBO.cixarilma_qayitma_Find_Tarix(array[index][0], 0).getTarix();
index++;
}
ad = list1.getAd();
});
DefaultTableModel model = new DefaultTableModel(
array,
new String[]{
"Ad / Soyad / Ata adı", "İşdən çıxarılma tarixi"
}
) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
table = autoResizeColWidth(table, model);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setModel(model);
table = new JTable(model);
JScrollPane pane = new JScrollPane(table);
add(pane);
}

最佳答案

找到答案。

list = new ArrayList<>(DBO.salary());
for (Iterator<Pojo> itr = list.iterator(); itr.hasNext();) {
Pojo element = itr.next();
if (element.getIsleyir() == 0) {
itr.remove();
}
if ("null".equals(element.getAd())) {
itr.remove();
}
if ("".equals(element.getAd())) {
itr.remove();
}
}
HashSet hs = new HashSet();
ArrayList al = new ArrayList();
list.stream().forEach((list1) -> {
hs.add(list1.getAd());
});
al.addAll(hs);
array = new String[list.size()][2];
al.stream().forEach((list1) -> {
if (ad == null ? list1 != null : !ad.equals(list1)) {
array[index][0] = (String) list1;
array[index][1] = DBO.cixarilma_qayitma_Find_Tarix(array[index][0], 0).getTarix();
index++;
}
ad = (String) list1;
});

关于java - 无法从 jtable 中删除重复项。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28130506/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com