Change Text Font for JLabel with HTML in Java

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

1K+ Views

To change text font, you can use the setFont() method of JLabel −label.setFont(new Font("Verdana", Font.PLAIN, 12));The following is an example to change text font for JLabel with HTML −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Label Example");       JLabel label;       label = new JLabel("" + "ABC");       label.setBounds(50, 50, 100, 30);       label.setFont(new Font("Verdana", Font.PLAIN, 12));       frame.add(label);       frame.setSize(500,300);       frame.setLayout(null);       frame.setVisible(true);    } }Output

What is IterMonthDates in Python

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

275 Views

itermonthdates() method will return all days for the month and all days before the start of the month or after an end of the month that are required to get a complete week.Exampleimport calendar #assigning variable to the calendar variable = calendar.Calendar() for day in variable.itermonthdates(2019, 5): print(day)Output2019-04-29 2019-04-30 2019-05-01 2019-05-02 2019-05-03 2019-05-04 2019-05-05 2019-05-06 2019-05-07 2019-05-08 2019-05-09 2019-05-10 2019-05-11 2019-05-12 2019-05-13 2019-05-14 2019-05-15 2019-05-16 2019-05-17 2019-05-18 2019-05-19 2019-05-20 2019-05-21 2019-05-22 2019-05-23 2019-05-24 2019-05-25 2019-05-26 2019-05-27 2019-05-28 2019-05-29 2019-05-30 2019-05-31 2019-06-01 2019-06-02Important to rememberlook into the output that calendar shows starts the previous month's date and ends with the after ... Read More

Get Node's First Child in a JTree with Java

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

399 Views

Let’s say we want the first child node of a node, then use the getFirstChild() method −node2.getFirstChild()Display the node’s first child on Console −System.out.println("The first child of node 2 = "+node2.getFirstChild());The following is an example to get this node’s first child in a JTree −package 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 ... Read More

Enable Display of Hidden Files in JFileChooser in Java

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

363 Views

Set the following to FALSE to enable the display of hidden files −JFileChooser file = new JFileChooser(); file.setFileHidingEnabled(false);The following is an example to enable the display of hidden files in a JFileChooser −Examplepackage my; import javax.swing.JFileChooser; public class SwingDemo {    public static void main(String[] args) {       JFileChooser file = new JFileChooser();       file.setMultiSelectionEnabled(false);       file.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);       file.setFileHidingEnabled(false);       int res = file.showOpenDialog(null);       if (res == JFileChooser.APPROVE_OPTION) {          java.io.File f = file.getSelectedFile();          System.err.println(f.getPath());       }   ... Read More

MongoDB Query for Partial Object in an Array

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

449 Views

Let us first create a collection with documents −> db.queryForPartialObjectDemo.insertOne({_id:new ObjectId(), "StudentDetails": [{"StudentId":1, "StudentName":"Chris"}]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdfcf55bf3115999ed51206") } > db.queryForPartialObjectDemo.insertOne({_id:new ObjectId(), "StudentDetails": [{"StudentId":2, "StudentName":"David"}]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdfcf55bf3115999ed51207") }Following is the query to display all documents from a collection with the help of find() method −> db.queryForPartialObjectDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cdfcf55bf3115999ed51206"),    "StudentDetails" : [       {          "StudentId" : 1,          "StudentName" : "Chris"       }    ] } {    "_id" ... Read More

Insert Binary Data into a Table Using JDBC

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

1K+ Views

SQL databases provide a datatype named Blob (Binary Large Object) in this, you can store large binary data like images.To store binary (stream) values into a table JDBC provides a method called setBinaryStream() in the PreparedStatement interface.It accepts an integer representing the index of the bind variable representing the column that holds values of type BLOB, an InputStream object holding the binary data and, inserts the given data in to the specified column.You can insert binary stream data into a table using this method as shown below −FileInputStream fin = new FileInputStream("javafx_logo.jpg"); pstmt.setBinaryStream(3, fin);ExampleLet us create a table with name ... Read More

Update Date Records with NULL Values in MySQL

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

1K+ Views

You can use IFNULL() for this. Let us first create a table −mysql> create table DemoTable -> ( -> added_date date, -> updated_date date -> ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-10', '2019-06-01'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-05-19', NULL); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(NULL, '2019-09-05'); Query OK, 1 row affected (0.18 sec)Display all records from the table using ... Read More

HTML DOM Input URL Maxlength Property

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

130 Views

The HTML DOM Input URL maxLength property returns/sets the maxLength property for input URL. If not defined this property returns ‘-1’.SyntaxFollowing is the syntax −Returning maxLength attributeinputURLObject.maxLengthSet maxLength property to a numberinputURLObject.maxLength = numberExampleLet us see an example of Input URL maxLength property − Live Demo Input URL maxLength    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } ... Read More

Variable Length Arguments for Macros in C

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

998 Views

We know that we can use variable length arguments for functions in C. For that we have to use ellipsis (…). Similarly for macros, we can use variable length arguments. Here also we have to include ellipsis, The ‘__VA_ARGS__’ is used to handle variable length arguments. Concatenation operator ‘##’ is used to concatenate the variable arguments.In this example, the Macro will take variable length argument like the printf() or scanf() function. In this macro, we will print the filename, line number, and error messages. The first argument is pr. This is used to determine the priority i.e. whether it is ... Read More

Create JLabel to Hold Multiline Text Using HTML in Java

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

1K+ Views

To hold multiline of text, set HTML under JLabel −JLabel = new JLabel("" + "Line1Line2",JLabel.LEFT);The above will create multiline text in the JLabel −Line1 Line2The following is an example to create JLabel to hold multiline of text −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Label Example");       JLabel label;       label = new JLabel("" + "Line1       Line2",JLabel.LEFT);       label.setBounds(100, 100, 100, 30);       label.setFont(new Font("Verdana", Font.PLAIN, 13));       frame.add(label);       frame.setSize(500,300);       frame.setLayout(null);       frame.setVisible(true);    } }Output

Advertisements