Select the First Column in a JTable with Java

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

649 Views

To select the first column in a JTable, use the setColumnSelectionInterval() method. Here, set the indexes as interval for one end as well as other end.For the first column, set the range as 0 and 0 since we want to only select the first column with index 0 −table.setColumnSelectionInterval(0, 0);The following is an example to select the first column in a JTable −Examplepackage my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();   ... Read More

Extract Particular Element in MongoDB Within a Nested Array

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

628 Views

To extract the particular element in MongoDB, you can use $elemMatch operator. Let us first create a collection with documents −> db.particularElementDemo.insertOne(    {       "GroupId" :"Group-1",       "UserDetails" : [          {             "UserName" : "John",             "UserOtherDetails" : [                {                   "UserEmailId" : "John123@gmail.com",                   "UserFriendName" : [                     ... Read More

HTML DOM ActiveElement Property

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

189 Views

The HTML DOM activeElement property is a read-only property to return the currently focused element in the document.Following is the syntax −document.activeElementLet us now see an example to implement the DOM activeElement property −Example Live Demo Heading Two Click in the element to get the active element. function display() { var a = document.activeElement.tagName; document.getElementById("myid").innerHTML = a; } OutputNow, click the element to display the same currently active element −

Difference Between Selenium WebDriver and TestNG

Adiya Dua
Updated on 30-Jul-2019 22:30:26

2K+ Views

WebDriver is a web automation framework which allows us to execute test across various browsers. It also allows us to create the test scripts in any programming language we want. WebDriver makes direct calls to the browser using each browser’s native support for automation.TestNG stands for Test Next Generation. It is an automation testing framework and uses annotations. Annotations are lines of code that control how the method below it will execute. The greatest advantage of TestNG is that we can generate test reports and know the number of scripts passed, failed or skipped. Failed test cases can be run ... Read More

Use WHERE with AND and OR in a Single MySQL Query

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

268 Views

Yes, we can use all of them in a single query. Let us first create a table −mysql> create table DemoTable    (    StudentId int,    StudentFirstName varchar(20),    StudentLastName varchar(20),    StudentAge int    ); Query OK, 0 rows affected (0.53 sec)Insert records in the table using insert command −mysql> insert into DemoTable values(100, 'John', 'Smith', 23); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(101, 'Carol', 'Taylor', 24); Query OK, 1 row affected (0.62 sec) mysql> insert into DemoTable values(103, 'John', 'Doe', 22); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable ... Read More

Get Driver Version using DatabaseMetaData in Java

Rishi Raj
Updated on 30-Jul-2019 22:30:26

358 Views

The getDriverVersion() method of the DatabaseMetaData interface returns the version of the JDBC driver used.To get the version of the JDBC driver used to connect with the database.Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a user in the database, as String variables.Get the DatabaseMetaData object with respect to the current connection using the getMetaData() method of ... Read More

Display First Selected Row in MySQL

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

228 Views

You can use ORDER BY for this. Let us first create a table −mysql> create table DemoTable    (    Value int    ); Query OK, 0 rows affected (0.20 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(8); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(18); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(11); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(9); Query OK, 1 row ... Read More

Select Multiple Rows in JTable with Java

Chandu yadav
Updated on 30-Jul-2019 22:30:26

2K+ Views

To select more than one row in a JTable, use the setRowSelectionInterval() method. Here, set the indexes as interval for one end as well as other end.For multiple rows in a range, set the range. Here, we are selecting rows from index 1 to index 2 i.e. two rows −table.setRowSelectionInterval(1, 2);The following is an example to select more than one row at a time in a JTable −Examplepackage my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ListSelectionModel; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void main(String[] args) {       JFrame ... Read More

Deep Flatten an Array in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

177 Views

Flattening an arrayFlattening an array is nothing but merging a group of nested arrays present inside a provided array. Flattening of an array can be done in two ways. 1) concat.apply() In the following example there are some nested arrays containing elements 3, 4, 5 and 6. After flattening them using concat() method we get the output as 1, 2, 3, 4, 5, 6, 9. Example Live Demo var arrays = [1, 2, [3, 4, [5, 6]], 9]; var merged = [].concat.apply([], arrays); documemt.write(merged); Output1, 2, 3, 4, 5, 6, 92) array.flat()In ... Read More

Display Value with addToSet in MongoDB Without Duplicates

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

207 Views

Use $addToSet operator to ensures that there are no duplicate items added to the set. Let us first create a collection with documents −> db.getDistinctDemo.insertOne({"Values":[100, 200]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cef69f9ef71edecf6a1f69d") } > db.getDistinctDemo.insertOne({"Values":[300, 100]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cef6a07ef71edecf6a1f69e") }Display all documents from a collection with the help of find() method −> db.getDistinctDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cef69f9ef71edecf6a1f69d"),    "Values" : [       100,       200    ] } {    "_id" : ObjectId("5cef6a07ef71edecf6a1f69e"),    "Values" : [       300, ... Read More

Advertisements