Filter JTable in Java

raja
Updated on 12-Feb-2020 07:54:44

5K+ Views

A JTable provides a very flexible possibility to create and display tables. The TableModel interface defines methods for objects that specify the contents of a table. The AbstractTableModel class is typically extended to provide a custom implementation of a model table. A JTable class provides the ability to edit tables using the method setCellEditor() allows an object of the TableCellEditor interface.We can filter a table using the setRowFilter() method of TableRowSorter class.Exampleimport java.awt.*; import java.awt.event.*; import java.util.regex.*; import javax.swing.*; import javax.swing.table.*; public class FilterTableTest extends JFrame {    private JTable table;    private TableModel model;    public FilterTableTest() {       setTitle("FilterTable Test");       ... Read More

Write MySQL Stored Procedure to Select All Data from a Table

Priya Pallavi
Updated on 12-Feb-2020 07:53:37

1K+ Views

To demonstrate it we are creating a procedure named ‘selectdetails()’ which will fetch all the records from table ‘student_detail’.mysql> Delimiter // mysql> Create Procedure selectdetails()    -> BEGIN    -> Select * from student_detail;    -> END// Query OK, 0 rows affected (0.00 sec)Now, after invoking this procedure, we will get all the records from ‘student_detail’ table.mysql> Delimiter ; mysql> CALL selectdetails(); +-----------+-------------+------------+ | Studentid | StudentName | address    | +-----------+-------------+------------+ |       100 | Gaurav      | Delhi      | |       101 | Raman       | Shimla     | |       103 | Rahul       | Jaipur     | |       104 | Ram         | Chandigarh | |       105 | Mohan       | Chandigarh | +-----------+-------------+------------+ 5 rows in set (0.00 sec) Query OK, 0 rows affected (0.01 sec)

Implement Mouse Right Click on Each Node of JTree in Java

raja
Updated on 12-Feb-2020 07:26:46

1K+ Views

A JTree is a subclass of JComponent class that can be used to display the data with the hierarchical properties by adding nodes to nodes and keeps the concept of parent and child node. Each element in the tree becomes a node. The nodes are expandable and collapsible. We can implement the mouse right-click on each node of a JTree using the mouseReleased() method of MouseAdapter class and need to call show() method of JPopupMenu class to show the popup menu on the tree node.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; public class JTreeRightClickTest extends JFrame {    public JTreeRightClickTest() {       ... Read More

Sort an Array of 10 Elements Using Heap Sort Algorithm in C++

Arjun Thakur
Updated on 12-Feb-2020 07:17:15

3K+ Views

Heap Sort is based on the binary heap data structure. In the binary heap the child nodes of a parent node are smaller than or equal to it in the case of a max heap, and the child nodes of a parent node are greater than or equal to it in the case of a min heap.An example that explains all the steps in Heap Sort is as follows.The original array with 10 elements before sorting is −207154101590237725This array is built into a binary max heap using max-heapify. This max heap represented as an array is given as follows.907720542515123710The root ... Read More

Using MySQL FIND_IN_SET Function to Retrieve Specific Records

Sai Nath
Updated on 12-Feb-2020 07:15:29

216 Views

We can get the record(s) as a result set by providing the particular string and name of the column as arguments of FIND_IN_SET() function. We also need to use WHERE clause with FIND_IN_SET() function. To understand it, we are using the data, given as below, from table ‘student_info’:mysql> Select * from student_info; +------+---------+----------+------------+ | id   | Name    | Address  | Subject    | +------+---------+----------+------------+ | 101  | YashPal | Amritsar | History    | | 105  | Gaurav  | Jaipur   | Literature | | 125  | Raman  | Shimla    | Computers  | +------+---------+----------+------------+ 3 rows in ... Read More

Display No Records Available Text in JTable in Java

raja
Updated on 12-Feb-2020 07:15:04

497 Views

A JTable is a subclass of JComponent class and it can be used to create a table with information displayed in multiple rows and columns. When a value is selected from a JTable, a TableModelEvent is generated, which is handled by implementing a TableModelListener interface.In the below program, we can display "No records available" text if the rows are not available in a JTable.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; public class NoRecordTableTest extends JFrame {    private JPanel panel;    private JTable table;    private JScrollPane scrollPane;    public NoRecordTableTest() {       panel = new JPanel();       panel.setLayout(new BorderLayout()); ... Read More

MySQL Query for Inequality Condition

Chandu yadav
Updated on 12-Feb-2020 07:09:16

146 Views

Inequality means NOT EQUAL TO and MySQL have two inequality operator, ‘’ and ‘!=’. following MySQL queries shows the inequality conditionsmysql> Select tender_value From estimated_cost1 WHERE Name_company != 'Chd Ltd.';The above query shows inequality condition because it have != operator.mysql> Select tender_value From estimated_cost1 WHERE Name_company 'Chd Ltd.';The above query shows inequality condition because it have operator.

Restrict Number of Digits in JPasswordField in Java

raja
Updated on 12-Feb-2020 07:02:45

479 Views

A JPasswordField is a subclass of JTextField and each character entered in a JPasswordField can be replaced by an echo character. This allows confidential input for passwords. The important methods of JPasswordField are getPassword(), getText(), getAccessibleContext() and etc. By default, we can enter any number of digits inside JPasswordField. If we want to restrict the digits entered by a user by implementing a DocumentFilter class and need to override the replace() method.Syntaxpublic void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationExceptionExampleimport java.awt.*; import java.awt.*; import javax.swing.*; import javax.swing.text.*; public class JPasswordFieldDigitLimitTest extends JFrame {    private JPasswordField passwordField;    private JPanel ... Read More

Add Different Font Styles to JList in Java

raja
Updated on 12-Feb-2020 06:54:41

753 Views

A JList is a subclass of JComponent class and it can be used to display a list of objects that allows the user to select one or more items. A JList can generate a ListSelectiionListener interface and need to implement the abstract method valueChanged(). A DefaultListModel class provides a simple implementation of a list model, which can be used to manage items displayed by a JList control. We can add the items to a JList using the addElement() method of the DefaultListModel class, we can also add items with different fonts to JList using HTML tags like for bold style text,   for italic style ... Read More

Implement Transparent JDialog in Java

raja
Updated on 12-Feb-2020 06:36:45

488 Views

A JDialog is a subclass of Dialog class and it does not hold minimize and maximize buttons at the top right corner of the window. There are two types of dialog boxes namely, modal and non-modal. The default layout for a dialog box is BorderLayout.In the below program, we can implement a transparent JDialog by customizing the AlphaContainer class and override the paintComponent() method.Exampleimport java.awt.*; import javax.swing.*; public class TransparentDialog {    public static void main (String[] args) {       JDialog dialog = new JDialog();       dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);       dialog.getRootPane().setOpaque(false);       dialog.setUndecorated(true);       dialog.setBackground(new Color (0, 0, ... Read More

Advertisements