Custom Cursor in Java Swing JDialog

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

792 Views

At first set the label on which you want the custom cursor to be visible on hover:JLabel label = new JLabel("Demo text! Hand cursor is visible on hover...");Now, set cursor to be visible as Hand Cursor instead of the default Cursor:label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));The following is an example to make a custom cursor appear when the user moves the mouse over some text:Exampleimport java.awt.Cursor; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; public class SwingDemo extends JFrame {    private void ShowDialog() {       JLabel label = new JLabel("Demo text! Hand cursor is visible on hover...");       label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));   ... Read More

Change JLabel Size in Java

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

9K+ Views

With Java Swing, you can set JLabel size as preferred size different than the default −JLabel label.setPreferredSize(new Dimension(250, 100));The following is an example to change JLabel size −Exampleimport java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("This is demo label!", JLabel.RIGHT);       label.setVerticalAlignment(JLabel.TOP);       label.setFont(new Font("Verdana", Font.PLAIN, 15));       label.setPreferredSize(new Dimension(250, 100));       label.setForeground(new Color(120, 90, 40));       label.setBackground(new ... Read More

Change Date Format with DATE_FORMAT in MySQL

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

687 Views

You can change the MySQL date format with a specific format using DATE_FORMAT(). Following is the syntax −select date_format(yourColumnName, yourFormatSpecifier) from yourTableName;Let us first create a table −mysql> create table DemoTable    (    ShippingDate date    ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2016-01-21'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('2018-05-24'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-12-31'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> ... Read More

Check Notifications Status for iOS App

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

2K+ Views

Notifications communicate important information to users of your app, regardless of whether your app is running on the user's device.For example, a sports app can let the user know when their favourite team scores. Notifications can also tell your app to download information and update its interface. Notifications can display an alert, play a sound, or badge the app's icon.You can read more about notification status here https://developer.apple.com/documentation/usernotificationsApple recommend to user UserNotifications framework, So let’s get started. We will be seeing very simple and easy solution to get the notification status.Step 1 − Firstly you need to import the UserNotifications ... Read More

Set Default Background Color for JTextPane in Java

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

953 Views

To set the default background color of JTextPane, use the SimpleAttributeSet and StyleConstants class. At first, create a new JTextPane −JTextPane pane = new JTextPane();Now, use the classes to set the style and color −SimpleAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setBackground(attributeSet, Color.white);Now, apply the set to the pane −pane.setCharacterAttributes(attributeSet, true);The following is an example to set default background color for JTextPane −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; public class SwingDemo {    public static void main(String args[]) throws BadLocationException {       JFrame frame = new ... Read More

Create Circular ProgressBar in Android

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

3K+ Views

This example demonstrate about How to create circular ProgressBar in Android.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/drawable/circular_progress_bar.xml.               Step 3 − Add the following code to res/drawable/circular_shape.xml     Step 4 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.sample ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; public class MainActivity extends AppCompatActivity ... Read More

What to Do When MongoDB Takes Too Much Time to Find a Record

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

108 Views

To reduce the time to find record in MongoDB, you can use index. Following is the syntax −db.yourCollectionName.createIndex({yourFieldName:1});You can follow the below approaches to create index for field names based on number, text, hash, etc.First ApproachLet us create an index. Following is the query −> db.takeLessTimeToSearchDemo.createIndex({"EmployeeName":1}); {    "createdCollectionAutomatically" : true,    "numIndexesBefore" : 1,    "numIndexesAfter" : 2,    "ok" : 1 }Second ApproachTo understand the above concept, let us create another index −> db.takeLessTimeToSearchDemo1.createIndex({"EmployeeName":"text"}); {    "createdCollectionAutomatically" : true,    "numIndexesBefore" : 1,    "numIndexesAfter" : 2,    "ok" : 1 }Third ApproachLet us now create another index −> db.takeLessTimeToSearchDemo2.createIndex({"EmployeeName":"hashed"}); {    "createdCollectionAutomatically" : true,    "numIndexesBefore" : 1,    "numIndexesAfter" : 2,    "ok" : 1 }

Insertion in a MySQL Table with Auto Increment Column

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

170 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId int NOT NULL AUTO_INCREMENT,    -> PRIMARY KEY(StudentId)    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command. Here, we have inserted a value, but since it is AUTO_INCREMENT, therefore, the default value would be visible −mysql> insert into DemoTable(StudentId) values(0); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output. The default AUTO_INCREMENT value 1 as the first value is visible ... Read More

Find Largest Prime Factor of a Number in C

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

3K+ Views

In this section, we will see how we can get the largest prime factor of a number in an efficient way. There is a number say n = 1092, we have to get the largest prime factor of this. The prime factors of 1092 are 2, 2, 3, 7, 13. So the largest is 13. To solve this problem, we have to follow this rule −When the number is divisible by 2, then store 2 as largest, and divide the number by 2 repeatedly.Now the number must be odd. Now starting from 3 to square root of the number, if ... Read More

Disable a JLabel in Java

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

562 Views

To disable a JLabel, use the setEnabled() method −JLabel label; label.setEnabled(false);The following is an example to disable a JLabel −package my; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("First Label", JLabel.RIGHT);       label.setVerticalAlignment(JLabel.TOP);       label.setFont(new Font("Verdana", Font.PLAIN, 15));       label.setPreferredSize(new Dimension(250, 100));       label.setForeground(new Color(120, 90, 40));       label.setBackground(new Color(100, 20, 70));       label.setEnabled(false);   ... Read More

Advertisements