Get JTextArea Font Information in Java

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

129 Views

Let’s say the following is our JTextArea −JTextArea textArea = new JTextArea("This is demo text.");Now, get the font using the Font class getFont() method as shown below −Font font = textArea.getFont(); System.out.println("Font = "+font);The following is an example to get JTextArea font information in Java −Examplepackage my; import java.awt.Font; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo {    SwingDemo(){       JFrame frame = new JFrame();       JTextArea textArea = new JTextArea("This is demo text.");       Font font = textArea.getFont();       System.out.println("Font = "+font);       frame.add(textArea);       frame.setSize(550, 300); ... Read More

Pass by Value and Pass by Reference in JavaScript

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

2K+ Views

Pass by value In pass by value, a function is called by directly passing the value of the variable as the argument. Changing the argument inside the function doesn’t affect the variable passed from outside the function. Javascript always pass by value so changing the value of the variable never changes the underlying primitive (String or number).In the following example, variable 'a' has assigned value 1. But inside function 'change' it got assigned with value 2. Since javascript is always a pass by value, the displayed output will be '1' but not '2'.ExampleLive Demo    let a = 1;   ... Read More

JDBC Class.forName vs DriverManager.registerDriver

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

6K+ Views

To connect with a database using JDBC you need to select get the driver for the respective database and register the driver. You can register a database driver in two ways −Using Class.forName() method − The forName() method of the class named Class accepts a class name as a String parameter and loads it into the memory, Soon the is loaded into the memory it gets registered automatically.Class.forName("com.mysql.jdbc.Driver");ExampleFollowing JDBC program establishes connection with MySQL database. Here, we are trying to register the MySQL driver using the forName() method.import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class RegisterDriverExample {    public static ... Read More

Limit Numbers to a Maximum Value in MySQL

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

233 Views

For this, you can use LEAST(). Following is the syntax −select least(yourColumnName, yourMaxValue) from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Number int    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(201); Query OK, 1 row affected (0.12 sec) ... Read More

Find Reminder of Array Multiplication Divided by n in C/C++

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

286 Views

Here we will see how to calculate the remainder of array multiplication after dividing the result by n. The array and the value of n are supplied by the user. Suppose the array is like {12, 35, 69, 74, 165, 54} so the multiplication will be (12 * 35 * 69 * 74 * 165 * 54) = 19107673200. Now if we want to get the remainder after diving this by 47 it will be 14.As we can see this problem is very simple. we can easily multiply the elements then by using modulus operator, it can get the result. ... Read More

Make the Program Sleep for X Milliseconds in C++

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

549 Views

Here we will see how to sleep for x (given by user) milliseconds in C++ program.To do this thing we can use different libraries. But here we are using the clock() function. The clock() will return the current CPU time. Here we will try to find the ending time from the clock, and the given x value. Then for that amount of time, we will run one blank while loop to take the time. Here one macro is used called CLOCKS_PER_SEC, this finds the number of clock ticks per second.Let us see the code to get the better idea about ... Read More

Create JFrame with No Border and Title Bar in Java

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

760 Views

To create a JFrame with no border and title bar, use setUndecorated() −JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(400, 300)); frame.setUndecorated(true);The following is an example to create JFrame with no border and title bar −Exampleimport java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setPreferredSize(new Dimension(400, 300)); frame.setUndecorated(true);       JPanel panel = new JPanel();       panel.add(new JLabel("Demo!"));       panel.add(new JButton(new AbstractAction("Close") {   ... Read More

Check If an Android App Can Show Notifications

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

249 Views

This example demonstrate about Android NotificationBuilder.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 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 ; public class MainActivity extends AppCompatActivity {    public static final String NOTIFICATION_CHANNEL_ID = "10001" ;    private final static String default_notification_channel_id = "default" ;    @Override    protected void ... Read More

Add Separator in a Toolbar with Java

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

245 Views

To add a separator, use the addSeparator() method. Let us first create a toolbar −JToolBar toolbar = new JToolBar();Now, we will create some components and set a separator to separate them as shown below −toolbar.add(new JTextArea(" Add name here")); toolbar.add(new JButton("Submit Name")); toolbar.addSeparator(); toolbar.add(new JTextArea(" Add age here")); toolbar.add(new JButton("Submit Age"));The following is an example to add separator in a ToolBar with Java −Examplepackage my; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JToolBar; public class SwingDemo {    public static void main(String[] args) {       JPanel panel = new JPanel(new BorderLayout());       ... Read More

Create Nested TitledBorder in Java

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

190 Views

Yes, we can create nested TitledBorder. Let us first create a component for which we will set the border −JLabel label = new JLabel();Now, we will create the 1st border −TitledBorder border = BorderFactory.createTitledBorder("Top Border"); border.setTitlePosition(TitledBorder.TOP);Following is how we will creater border 2. We have set the 1st border here −TitledBorder border2 = new TitledBorder(border, "Bottom CENTER Border", TitledBorder.CENTER, TitledBorder.BOTTOM);Now, set it for the label component −label.setBorder(border2);The following is an example to create nested TitledBorder in Java −package my; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.TitledBorder; public class SwingDemo {    public static ... Read More

Advertisements