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
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
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 }
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
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
The memory leak occurs, when a piece of memory which was previously allocated by the programmer. Then it is not deallocated properly by programmer. That memory is no longer in use by the program. So that place is reserved for no reason. That’s why this is called the memory leak.For the memory leak, some block of memory may have wasted. If the system has enough memory, in that case also this may slow down the performance.Examplevoid my_func() { int *data = new int; *data = 50; }Here the problem is *data pointer is never deleted, so memory is ... Read More
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
To get possible values for set field, you can use below syntax −desc yourTableName yourSetColumnName;Let us first create a table −mysql> create table DemoTable ( Game set('Chess','Pig Dice','29 Card') ); Query OK, 0 rows affected (0.60 sec)Following is the query to get available values for set field −mysql> desc DemoTable Game;This will produce the following output −+-------+-----------------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-----------------------------------+------+-----+---------+-------+ | Game | set('Chess','Pig Dice','29 Card') | YES | | NULL | | +-------+-----------------------------------+------+-----+---------+-------+ 1 row in set (0.02 sec)
To get the list of notifications which are active on your status bar tray we are going to use getdeliverednotifications, you can read more about it here.https://developer.apple.com/documentation/usernotifications/unusernotificationcenterhttps://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649520-getdeliverednotificationsWhile it is know that we cannot get the notifications from all apps as that would be a privacy violation, but we can get the notification for our applicationApple provide getDeliveredNotifications(completionHandler:)Which returns a list of the app’s notifications that are still displayed in Notification Center.You can write the following code depending upon your need.UNUserNotificationCenter.current().getDeliveredNotifications { (notifications) in print(notifications) }Read More
To set style for text in JTextPane, use setItalic() or setBold() that sets italic or bold style for font respectively.Following is our JTextPane component −JTextPane pane = new JTextPane();Now, use the StyleConstants class to set style for the JTextPane we created above. We have also set the background and foregound color −SimpleAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setItalic(attributeSet, true); StyleConstants.setForeground(attributeSet, Color.black); StyleConstants.setBackground(attributeSet, Color.orange); pane.setCharacterAttributes(attributeSet, true);The following is an example to set style 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 ... Read More