Make a JTree Editable in Java

George John
Updated on 30-Jul-2019 22:30:26

612 Views

To make JTree editable in Java, use the TreeCellEditor class. With that, set the setEditable() method to true −TreeCellEditor editor = new DefaultCellEditor(textField); tree.setEditable(true); tree.setCellEditor(editor);The above will make the tree editable. The following is an example to make a JTree editable in Java −Examplepackage my; import javax.swing.DefaultCellEditor; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeCellEditor; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing");       DefaultMutableTreeNode node2 = ... Read More

Match Multiple Criteria Inside an Array with MongoDB

Anvi Jain
Updated on 30-Jul-2019 22:30:26

302 Views

For this, use aggregate framework with the $elemMatch operator. Let us first create a collection with documents −> db.matchMultipleCriteriaDemo.insertOne({    "EmployeeDetails": [       {"EmployeeName": "Chris", "Salary": 45000, "Language":"Java"},       {"EmployeeName": "Robert", "Salary": 41000, "Language":"Python"}    ] }); {    "acknowledged" : true,    "insertedId" : ObjectId("5cea3bf0ef71edecf6a1f689") } > db.matchMultipleCriteriaDemo.insertOne({    "EmployeeDetails": [       {"EmployeeName": "David", "Salary": 55000, "Language":"C++"},       {"EmployeeName": "Bob", "Salary": 61000, "Language":"C"}    ] }); {    "acknowledged" : true,    "insertedId" : ObjectId("5cea3bf1ef71edecf6a1f68a") }Following is the query to display all documents from a collection with the help of find() ... Read More

Implement MySQL ORDER BY Without Using ASC or DESC

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

156 Views

For this, you can use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable -> ( -> Number int -> ); Query OK, 0 rows affected (2.25 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.91 sec) mysql> insert into DemoTable values(60); Query OK, 1 row affected (0.69 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.72 sec) mysql> insert into DemoTable values(800); Query OK, 1 row affected (0.75 sec)Display all records ... Read More

Exclude a Specific Record in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

435 Views

You can exclude a specific record in SQL using not equal to operator(!=). Let us first create a table−mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(20),    ClientCountryName varchar(10)    ); Query OK, 0 rows affected (0.64 sec)Insert records in the table using insert command −mysql> insert into DemoTable(ClientName, ClientCountryName) values('John', 'US'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(ClientName, ClientCountryName) values('David', 'AUS'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(ClientName, ClientCountryName) values('Mike', 'UK'); Query OK, 1 row affected (0.14 sec)Display all records from the ... Read More

Java DatabaseMetaData getColumns Method with Example

Arushi
Updated on 30-Jul-2019 22:30:26

4K+ Views

This method retrieves the description of the columns of a table. It accepts 4 parameters −catalog - A string parameter representing the name (or, name pattern) of the catalog (database in general) in which the table (that contains the columns of which you need to retrieve the description about) exists. pass "" to get the description of the columns in tables with no catalog and, pass null if you don't want to use catalog and thus narrow the search.schemaPattern - A String parameter representing the name (or, name pattern) of the schema of the table, pass "" if in case ... Read More

MySQL Alias Shorthand

Smita Kapse
Updated on 30-Jul-2019 22:30:26

270 Views

You need to give name explicitly or you can remove AS command. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20)    ); Query OK, 0 rows affected (0.21 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Name) values('Larry'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(Name) values('Sam'); Query OK, 1 row affected (0.06 sec)Display all records from the table using select statement −mysql> select ... Read More

Create Default Cell Editor with TextBox in Java

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

280 Views

Create a JTextBox first −JTextField textField = new JTextField();Set the above JTextFile for the Default Cell Editor −TreeCellEditor editor = new DefaultCellEditor(textField); tree.setEditable(true); tree.setCellEditor(editor);The following is an example to create a default cell editor with textbox −Examplepackage my; import javax.swing.DefaultCellEditor; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeCellEditor; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing");       DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Electronics");       DefaultMutableTreeNode node3 ... Read More

Use MongoDB Field Value as Pattern in Regex

Smita Kapse
Updated on 30-Jul-2019 22:30:26

191 Views

Yes, for this, use $indexOfCP operator along with aggregate framework. Let us first create a collection with documents −> db.patterDemo.insertOne(    {       "ClientName": "John", "ClientWebsiteName":"webbuziness.com/John/business"    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cea40acef71edecf6a1f68d") } > db.patterDemo.insertOne(    {       "ClientName": "Carol", "ClientWebsiteName":"solvecoding.com/business"    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cea40acef71edecf6a1f68e") }Following is the query to display all documents from a collection with the help of find() method −> db.patterDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cea40acef71edecf6a1f68d"),    "ClientName" : "John",    "ClientWebsiteName" : "abcd.com" ... Read More

C Program to Find the Area of a Circle

Sharon Christine
Updated on 30-Jul-2019 22:30:26

17K+ Views

The area is a quantity that represents the extent of the figure in two dimensions. The area of a circle is the area covered by the circle in a two dimensional plane.To find the area of a circle, the radius[r] or diameter[d](2* radius) is required.The formula used to calculate the area is (π*r2) or {(π*d2)/4}.Example CodeTo find the area of a circle using radius. Live Demo#include int main(void) {    float pie = 3.14;    int radius = 6;    printf("The radius of the circle is %d " , radius);    float area = (float)(pie* radius * radius);    printf("The ... Read More

Get Total Number of Rows in a MySQL Database

George John
Updated on 30-Jul-2019 22:30:26

3K+ Views

To get the total number of rows in a MySQL database, you can use aggregate function SUM() along with inbuilt column TABLE_ROWS from INFORMATION_SCHEMA.TABLES.The syntax is as follows−SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database();Let’s say we are using the database with the name ‘sample’.Now we will get the total number of rows in a MySQL database−mysql> SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = database();This will produce the following output−+-----------------+ | SUM(TABLE_ROWS) | +-----------------+ | 2043 | +-----------------+ 1 row in set (22.11 sec)

Advertisements