Тёмный

Java Project Tutorial - How to Create a Custom Table and Scrollbars Using Graphics In Java NetBeans 

1BestCsharp blog
Подписаться 122 тыс.
Просмотров 685
50% 1

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 3   
@1BestCsharpblog
@1BestCsharpblog 5 месяцев назад
▶ ▶ ▶ LEAVE A LIKE FOR MORE PROJECTS 👍👍👍 ▶ Create a Custom CheckBox: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-alkcVURyIx8.html ▶ Create a Custom RadioButton: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-5FeG6OhJg10.html
@sulevanG
@sulevanG 5 месяцев назад
Hi i really needed your help. Can you make a video about how to make a jtable with disabled duplicate entry? For example when i put James in the jtable i shouldn't be able to put another one. Only limit it in 1?
@1BestCsharpblog
@1BestCsharpblog 5 месяцев назад
import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashSet; public class UniqueEntryJTableDemo extends JFrame { private JTable table; private DefaultTableModel model; private JTextField textField; private HashSet uniqueEntries; public UniqueEntryJTableDemo() { setTitle("Unique Entry JTable"); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(400, 300); // Initialize HashSet to store unique entries uniqueEntries = new HashSet(); // Create table model model = new DefaultTableModel(); model.addColumn("Name"); // Create JTable with the model table = new JTable(model); // Create JTextField for input textField = new JTextField(20); // Create JButton to add entry JButton addButton = new JButton("Add"); addButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addEntry(); } }); // Create JPanel for input components JPanel inputPanel = new JPanel(); inputPanel.add(textField); inputPanel.add(addButton); // Add components to JFrame add(new JScrollPane(table), BorderLayout.CENTER); add(inputPanel, BorderLayout.SOUTH); } private void addEntry() { String entry = textField.getText().trim(); if (!entry.isEmpty() && !uniqueEntries.contains(entry)) { uniqueEntries.add(entry); // Add to HashSet model.addRow(new Object[]{entry}); // Add to JTable textField.setText(""); // Clear text field } else { JOptionPane.showMessageDialog(this, "Duplicate entry or empty string!", "Error", JOptionPane.ERROR_MESSAGE); } } public static void main(String[] args) { new UniqueEntryJTableDemo().setVisible(true); } }
Далее
这到底是怎么做到的 #路飞#海贼王
00:10
Просмотров 4,4 млн
小丑调戏黑天使的后果#short #angel #clown
00:16
Think Fast, Talk Smart: Communication Techniques
58:20
Learn Microsoft Active Directory (ADDS) in 30mins
36:26
JTable Custom Cell Button Action using Java Swing
10:24
Tables in NextJs Using shadcn/ui and TanStack Table
37:49