Set Alignment of JLabel Content Along Y-Axis in Java

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

559 Views

To set the alignment of the label content along the Y axis, use the setVerticalAlignment() 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("Product Name "); label.setPreferredSize(new Dimension(190, 100)); label.setOpaque(true); label.setBackground(Color.ORANGE);Now, we will align the label content along the Y axis −label.setVerticalAlignment(JLabel.CENTER);The following is an example to set the alignment of the JLabel content along the Y 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 javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Our Frame ... Read More

Get Tag Count in MongoDB Query Results Based on List of Names

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

175 Views

You can use $in operator. Let us first create a collection with documents −> db.tagCountDemo.insertOne({"ListOfNames":["John", "Sam", "Carol"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd64b387924bb85b3f48944") } > db.tagCountDemo.insertOne({"ListOfNames":["Bob", "David", "John"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd64b4b7924bb85b3f48945") } > db.tagCountDemo.insertOne({"ListOfNames":["Mike", "Robert", "Chris"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd64b5d7924bb85b3f48946") } > db.tagCountDemo.insertOne({"ListOfNames":["James", "Carol", "Jace"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd64b717924bb85b3f48947") }Following is the query to display all documents from a collection with the help of find() method −> db.tagCountDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd64b387924bb85b3f48944"),    "ListOfNames" : ... Read More

isnormal in C++

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

131 Views

In this section we will see the isnormal() function in C++. This function is present in the cmath library. This function is used to check whether a number is normal or not. The numbers that are considered as non-normal are zeros, infinity or NAN.This function takes float, double or long double values as argument. Returns 1 if the number is normal, otherwise returns 0.Example Live Demo#include #include using namespace std; int main() {    cout

Create Enum with Custom Values in Java

Venkata Sai
Updated on 30-Jul-2019 22:30:26

8K+ Views

Enumeration (enum) in Java is a datatype which stores a set of constant values (Strings in general). You can use enumerations to store fixed values such as days in a week, months in a year etc.enum Days { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }Custom values to the constantsInstead of declaring just string constants in an enum, you can also have values to these constants as −enum Vehicles { ACTIVA125(80000), ACTIVA5G(70000), ACCESS125(75000), VESPA(90000), TVSJUPITER(75000); }Whenever, you need to assign custom values to the constants of an enum −To hold the value of each ... Read More

HTML DOM Input File Upload Name Property

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

122 Views

The HTML DOM FileUpload name property returns and modify the value of the name attribute of an fileupload input type in HTML.SyntaxFollowing is the syntax −1. Returning nameobject.name2. Setting nameobject.name=”text”ExampleLet us see an example of FileUpload name property − Live Demo HTML DOM name Property    body{       background-color:#397367;       color:#fff;       padding:20px;    }    .btn{       display:block;       background-color:#22223B;       color:#fff;       border:none;       padding:0.5rem;       border-radius:50px;       width:80%;       margin:10px;    }   ... Read More

HTML DOM Input Email Placeholder Property

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

147 Views

The HTML DOM Input Email placeholder property sets/returns a string generally used to give hints to user of what the input text will look like.SyntaxFollowing is the syntax −Returning string valueinputEmailObject.placeholderSetting placeholder to stringValueinputEmailObject.placeholder = stringValueExampleLet us see an example of Input Email placeholder property − Input Email placeholder    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } ... Read More

Print an Array with Numbers Having 1, 2, and 3 as Digits in Ascending Order

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

733 Views

Here, the task is to print those number in an array having 1, 2 and 3 as digits in their numbers and if their is no such number than the output must be -1Input : arr[] = {320, 123, 124, 125, 14532, 126, 340, 123400, 100032, 13, 32, 3123, 1100} Output : 123 3123 14532 100032 123400 Since the array have values with digits 1, 2 and 3 it wouldn’t return -1 and print 5 values that Contain 1, 2 and 3 in their respective numbers.AlgorithmSTART Step 1 -> Declare array with elements of int type as arr Step ... Read More

MongoDB Query to Match Each Element in a Document's Array to a Condition

Samual Sam
Updated on 30-Jul-2019 22:30:26

216 Views

You can use every() in MongoDB for this. Let us create a collection with documents −> db.arrayConditionDemo.insertOne({"Name":"John", "Marks":[40, 43, 45]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdbd06de8cc557214c0e1a") } > db.arrayConditionDemo.insertOne({"Name":"Mike", "Marks":[45]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdbd17de8cc557214c0e1b") } > db.arrayConditionDemo.insertOne({"Name":"Chris", "Marks":[43, 45, 59, 69, 78, 89]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cbdbd3cde8cc557214c0e1c") }Display all documents from a collection with the help of find() method. The query is as follows −> db.arrayConditionDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cbdbd06de8cc557214c0e1a"),    "Name" : "John",    "Marks" : [       ... Read More

Regex to Ignore a Specific Character in MongoDB

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

1K+ Views

You can use regular expression along with $not operator to ignore a specific character and display rest of them. Let us first create a collection with documents −> db.regexDemo.insertOne({"CustomerId":"Customer#1234", "CustomerName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc7428f8f9e6ff3eb0ce436") } > db.regexDemo.insertOne({"CustomerId":"Customer5678", "CustomerName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc7429e8f9e6ff3eb0ce437") } > db.regexDemo.insertOne({"CustomerId":"Customer#777", "CustomerName":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc742ae8f9e6ff3eb0ce438") } > db.regexDemo.insertOne({"CustomerId":"Customer777", "CustomerName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc742bc8f9e6ff3eb0ce439") }Following is the query to display all documents from a collection with the help of find() method −> db.regexDemo.find().pretty();This will produce the ... Read More

Get a Node's Parent in a JTree with Java

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

886 Views

Let’s say we want the parent of a node, then use the getParent() method -node3.getFirstChild()You can also get the parent of child node. Here, “nine” is the child node −nine.getParent()The output is as follows displaying this node’s parent on Console −Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; 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 (Product1 - P66778)");       DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Accessories (Product2 - P66779)");   ... Read More

Advertisements