Set Alignment of JLabel Content Along the X-Axis in Java

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

810 Views

To set the alignment of the label content along the X axis, use the setHorizontalAlignment() method. Let us first set a label component. We have set the label background color as well so that we can check the alignment of the label’s content properly −JLabel label = new JLabel("Team "); label.setPreferredSize(new Dimension(190, 100)); label.setOpaque(true); label.setBackground(Color.BLUE); label.setForeground(Color.WHITE);Now, we will align the label content along the X axis −label.setHorizontalAlignment(JLabel.CENTER);The following is an example to set the alignment of the JLabel content along the X axis −Examplepackage my; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import ... Read More

Sort MongoDB Documents by Subdocument Match

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

332 Views

To sort by sub-document match, you can use aggregate framework. Let us first create a collection with documents −> db.sortBySubDocumentsDemo.insertOne(    {       "StudentName": "Chris",       "StudentDetails": [          {             "Age":21,             "StudentScore":91          },          {             "Age":22,             "StudentScore":99          },          {             "Age":21,             "StudentScore":93   ... Read More

Thick Ethernet vs Thin Ethernet

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

6K+ Views

Thick EthernetThick Ethernet was the first commercially available form of cabling supported by Ethernet. It is technically known as 10-BASE-5. Here, 10 is the maximum throughput, i.e. 10 Mbps, BASE denoted use of baseband transmission, and 5 refers to the maximum segment length of 500 metres (1, 600 ft). This type of cabling allows 100 stations to be connected to it by vampire taps.Thin EthernetThin Ethernet, popularly known as cheapernet or thinnet, is among the family of Ethernet standards that uses thinner coaxial cable as a transmission media. It is technically known as 10-BASE-2.Here, 10 is the maximum throughput, i.e. ... Read More

HTML DOM Input FileUpload Files Property

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

176 Views

The HTML DOM FileUpload files property returns a FileList object which contains all the files that are selected by the file upload button.SyntaxFollowing is the syntax −object.filesExampleLet us see an example of FileUpload files property − Live Demo    body{       text-align:center;       background-color:#52B2CF;       color:#fff;    }    .btn{       background-color:coral;       border:none;       height:2rem;       border-radius:50px;       width:60%;       margin:1rem auto;       display:block;       color:#fff;       outline:none;    }    .show{   ... Read More

HTML DOM Input Email Pattern Property

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

334 Views

The HTML DOM Input Email pattern property sets/returns the regular expression corresponding to Email Input. The pattern attribute’s value is checked against the text typed in an email field.SyntaxFollowing is the syntax −Returning regular expressioninputEmailObject.patternSetting pattern to regular expressioninputEmailObject.pattern = ‘RegExp’ExampleLet us see an example of Input Email pattern property − Live Demo Input Email pattern    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="submit"] {       border-radius: 10px; ... Read More

Print Matrix in Diagonal Pattern

Sunidhi Bansal
Updated on 30-Jul-2019 22:30:26

469 Views

Given a 2d array of n*n and the task is to find the antispiral arrangement of the given matrixInput : arr[4][4]={1,2,3,4,    5,6,7,8,    9,10,11,12    13,14,15,16} Output : 1 6 11 16 4 7 10 13AlgorithmSTART Step 1 -> declare start variables as r=4, c=4, i and j Step 2 -> initialize array as mat[r][c] with elements Step 3 -> Loop For i=0 and i print Step 5 -> Loop For i=0 and i

Retrieve a Stream from a List in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:26

168 Views

Let us first create a List:List list = Arrays.asList(25, 50, 100, 200, 250, 300, 400, 500);Now, create a stream from the List:Stream stream = list.stream(); Arrays.toString(stream.toArray()));The following is an example to retrieve a Stream from a ListExampleimport java.util.Arrays; import java.util.List; import java.util.stream.Stream; public class Demo {    public static void main(String[] args) {       List list = Arrays.asList(25, 50, 100, 200, 250, 300, 400, 500);       System.out.println("List elements...");       for (int res : list)       {          System.out.println(res);       }       Stream stream = list.stream();       System.out.println("Stream = "+Arrays.toString(stream.toArray()));    } }OutputList elements... 25 50 100 200 250 300 400 500 Stream = [25, 50, 100, 200, 250, 300, 400, 500]

Android Notification Example with Vibration, Sound, Action and Big View Styles

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

495 Views

This example demonstrate about Android Notification Example with Vibration, Sound, Action and Big View StylesStep 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 src/MainActivity.javapackage app.tutorialspoint.com.notifyme; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity {    private final static String default_notification_channel_id = "default";    @Override    protected void onCreate (Bundle ... Read More

Perform AND Query on an Array in MongoDB

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

201 Views

To get the same result like AND in MongoDB, use the $all operator. Let us first create a collection with documents −> db.andQueryDemo.insertOne({"StudentName":"Carol Taylor", "FavouriteSubject":["C", "Java", "MongoDB", "MySQL"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc73e7a8f9e6ff3eb0ce433") } > db.andQueryDemo.insertOne({"StudentName":"David Miller", "FavouriteSubject":["C++", "Java", "MongoDB", "SQL Server"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc73ea48f9e6ff3eb0ce434") } > db.andQueryDemo.insertOne({"StudentName":"Carol Taylor", "FavouriteSubject":["Python", "PL/SQL"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc73ed38f9e6ff3eb0ce435") }Following is the query to display all documents from a collection with the help of find() method −> db.andQueryDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cc73e7a8f9e6ff3eb0ce433"),   ... Read More

C++ Program to Perform Sorting Using B-Tree

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

446 Views

Here we will see how to get the sorted sequence using B-Tree. The B-tree is n-ary tree. To get the sorted sequences, we can create a B-tree, then add the numbers into it. Here the B-tree can hold maximum 5 nodes. If number of nodes increases, split the node and form new level. As the nodes are holding few number of elements like 5 (at most), we are using Bubble sorting techniques to sort them. as the number of elements is very low, then it will not affect too much on its performance.After traversing the tree, we will get all ... Read More

Advertisements