Create Titled Border for a Component in Java

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

2K+ Views

To create a titled border for a component in Java, use the createTitledBorder() method. Let’s say we have a panel and we need to set a titled border to it. Here’s our panel −JPanel panel = new JPanel();Now, set the border and set the text for the tites border −panel.setBorder(BorderFactory.createTitledBorder(    BorderFactory.createEtchedBorder(), "My Demo Table", TitledBorder.LEFT, TitledBorder.TOP));The following is an example to create a titled border −Examplepackage my; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();   ... Read More

Convert String Duration to Minutes in MySQL

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

146 Views

You can use str_to_date() for this conversion. Let us first create a table −mysql> create table DemoTable    (    stringDate varchar(100)    ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('1h 15 min'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('2h 30 min'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+------------+ | stringDate | +------------+ | 1h 15 min | | 2h 30 min | +------------+ 2 rows in set ... Read More

Pass Value in WHERE Clause on PreparedStatement Using JDBC

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

4K+ Views

To execute a statement with Where clause using PreparedStatement. Prepare the query by replacing the value in the clause with place holder “?” and, pass this query as a parameter to the prepareStatement() method.String query = "SELECT * FROM mobile_sales WHERE unit_sale >= ?"; //Creating the PreparedStatement object PreparedStatement pstmt = con.prepareStatement(query);Later, set the value to the place holder using the setXXX() method of the PreparedStatement interface.pstmt.setInt(1, 4000); ResultSet rs = pstmt.executeQuery();ExampleLet us create a table with name mobile_sales in MySQL database using CREATE statement as shown below −CREATE TABLE mobile_sales (    mobile_brand VARCHAR(255),    unit_sale INT );Now, we ... Read More

MySQL Query with OR, AND Conditions

Kumar Varma
Updated on 30-Jul-2019 22:30:26

182 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name, Age) values('John', 21); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Name, Age) values(Null, 20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name, Age) values('David', 23); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Name, Age) values('Carol', null); ... Read More

C++ Program for Cocktail Sort

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

640 Views

The Cocktail sort is another variation of bubble sort. In the bubble sort technique, it always searches from left to right, and finds the largest element at the end, in the second phase it finds the second largest element at the second last position. This sorting technique traverses in both directions alternatively. Let us see the algorithm to understand the idea.Algorithmcocktail(array, n)Begin    flag := true    start := 0, end := n-1    while flag is set, do       flag := false       for i in range start to end-1, do         ... Read More

Rule of Three in C++

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

339 Views

The Rule of three is a rule of thumb when using C++. This is kind of a good practice rule that says that If your class needs any ofa copy constructor, an assignment operator, or a destructor, defined explicitly, then it is likely to need all three of them.Why is this? It’s because, if your class requires any of the above, it is managing dynamically allocated resources and would likely be needing the other to successfully achieve that. For example, if you require an assignment operator, you would be creating copies of objects currently being copied by reference, hence allocating ... Read More

Extending Namespace and Unnamed Namespace in C++

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

294 Views

Here we will see how we can extend some namespace, and how the unnamed or anonymous name space can be used.Sometimes we can define one namespace. Then we can write the namespace again with the same definition. If the first one has some member, and second one has some other members, then the namespace is extended. We can use all of the members from that namespace.Example#include using namespace std; namespace my_namespace {    int my_var = 10; } namespace my_namespace { //extending namespace    int my_new_var = 40; } main() {    cout

Change Notification Background Colour in Android

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

2K+ Views

This example demonstrate about How can I marquee the text content in Android Notification.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to res/layout/custom_notification_layout.xml.             Step 4 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.os.Bundle ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; import android.widget.RemoteViews ; public class MainActivity ... Read More

Search a Sub-Field on MongoDB

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

311 Views

To search a sub-filed in MongoDB, you can use double quotes along with dot notation. Let us first create a collection with documents −> db.searchSubFieldDemo.insertOne( ...   { ...      "UserDetails": ...      {"UserEmailId":"John123@gmail.com", "UserAge":21} ...   } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3d909edc6604c74817ce2") } > db.searchSubFieldDemo.insertOne( { "UserDetails": {"UserEmailId":"Carol@yahoo.com", "UserAge":26} } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3d9a4edc6604c74817ce3") }Following is the query to display all documents from a collection with the help of find() method −> db.searchSubFieldDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd3d909edc6604c74817ce2"),    "UserDetails" ... Read More

Create Compound Border for a Component in Java

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

619 Views

Composed border consists of two or more borders i.e. border around a border. We can create it for a component in Java using the createCompoundBorder() method.Let’s say the following is our component −JLabel label; label = new JLabel("This has compound border (border around a border)!");Now, set the compound border −label.setBorder(BorderFactory.createCompoundBorder(BorderFactory    .createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()));The following is an example to create a compound border for a component −Examplepackage my; import javax.swing.BorderFactory; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       JLabel ... Read More

Advertisements