How to display the first element in a JComboBox in Java

Nancy Den
Updated on 30-Jul-2019 22:30:26

514 Views

To display the first element in a JComboBox, use the getSelectedIndex():comboBox.setSelectedIndex(0);The following is an example to display the first element in a JComboBox in Java:Exampleimport java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextArea; public class SwingDemo {    public static void main(String[] args) {       JPanel panel = new JPanel(new BorderLayout());       String[] strArr = new String[] { "Laptop", "Mobile", "Desktop", "Tablet" };       JComboBox comboBox = new JComboBox(strArr);       panel.add(comboBox, BorderLayout.NORTH);       JTextArea text = new JTextArea(5, 5);       panel.add(text, ... Read More

How to close the notification panel after notification button is clicked in Android?

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

1K+ Views

This example demonstrate about How to close the notification panel after notification button is clicked in AndroidStep 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.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity { ... Read More

IPC using Message Queues

George John
Updated on 30-Jul-2019 22:30:26

3K+ Views

Why do we need message queues when we already have the shared memory? It would be for multiple reasons, let us try to break this into multiple points for simplification −As understood, once the message is received by a process it would be no longer available for any other process. Whereas in shared memory, the data is available for multiple processes to access.If we want to communicate with small message formats.Shared memory data need to be protected with synchronization when multiple processes communicating at the same time.Frequency of writing and reading using the shared memory is high, then it would ... Read More

How to set the alignment of the JLabel content along the Y axis on the top in Java

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

104 Views

To set the alignment of the label’s content along the Y axis on the top, use the setVerticalAlignment() method and set the location. 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("Favourite Movie"); label.setPreferredSize(new Dimension(190, 100)); label.setOpaque(true); label.setBackground(Color.GREEN); label.setForeground(Color.WHITE);Now, we will align the label content along the Y axis on the top by seeting location as TOP −label.setVerticalAlignment(JLabel.TOP);The following is an example to set the alignment of the JLabel content along the Y axis on the ... Read More

Getting a list of values by using MongoDB $group?

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

1K+ Views

To get a list of values, use $group aggregation along with $push operator. Let us first create a collection with documents −> db.groupByDemo.insertOne({"UserName":"John", "Subject":"MongoDB"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f0457806ebf1256f136") } > db.groupByDemo.insertOne({"UserName":"Larry", "Subject":"MySQL"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f0657806ebf1256f137") } > db.groupByDemo.insertOne({"UserName":"John", "Subject":"Java"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f0d57806ebf1256f138") } > db.groupByDemo.insertOne({"UserName":"John", "Subject":"C"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f1357806ebf1256f139") } > db.groupByDemo.insertOne({"UserName":"Larry", "Subject":"SQL Server"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd69f1c57806ebf1256f13a") }Following is the query to display all documents from a collection with the help ... Read More

HTML placeholder Attribute

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

303 Views

The placeholder attribute of the element is used to set a hint for the input that would give a short description about what is expected in that particular input. This attribute works for the following input types − text, url, search, email, password and tel. It introduced in HTML5.Following is the syntax −Here, placeholder_text is the short hint i.e. placeholder which would be visible to the users whenever they will visit that web page.Let us now see an example to implement the placeholder attribute of the element −Example Live Demo Register Id − ... Read More

Disable Scroll View Programmatically in iOS?

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

878 Views

Scroll View is one of the most difficult and complicated topic an iOS Developer come across. Here we will be seeing how to disable Scroll View Programmatically.For disabling the same we need to make the “isScrollEnabled” property of our scroll view to false.Copy the below code in your file.import UIKit class ViewController: UIViewController {    @IBOutlet var scrollView: UIScrollView!    override func viewDidLoad() {       super.viewDidLoad()       scrollView.isScrollEnabled = false    }    override func didReceiveMemoryWarning() {       super.didReceiveMemoryWarning()       // Dispose of any resources that can be recreated.    } }

Multiply values of two columns and display it a new column in MySQL?

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

3K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> NumberOfItems int,    -> Amount int    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(4, 902); Query OK, 1 row affected (0.45 sec) mysql> insert into DemoTable values(5, 1000); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(3, 80); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+---------------+--------+ | NumberOfItems | Amount | +---------------+--------+ |   ... Read More

C++ Program for Common Divisors of Two Numbers?

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

206 Views

Here we will see how we can get the number of common divisors of two numbers. We are not going to find all common divisors, but we will count how many common divisors are there. If two numbers are like 12 and 24, then common divisors are 1, 2, 3, 4, 6, 12. So there are 6 common divisors, so the answer will be 6.AlgorithmcountCommonDivisor(a, b)begin    count := 0    gcd := gcd of a and b    for i := 1 to square root of gcd, do       if gcd is divisible by 0, then   ... Read More

HTML DOM lastModified Property

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

35 Views

The HTML DOM lastModified property returns the date and time the current document was last modified.SyntaxFollowing is the syntax −Returning date and time −document.lastModifiedExampleLet us see an example for HTML DOM lastModified property − Live Demo HTML DOM lastModified    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } HTML-DOM-lastModified NOTICE:    var divDisplay = document.getElementById("divDisplay");    var textSelect = document.getElementById("textSelect");    function getNoticeIssuedTime() {       divDisplay.textContent = 'Notice was issued on: '+document.lastModified;    } OutputThis will produce the following output −Before clicking ‘When was this issued?’ button −After clicking ‘When was this issued?’ button −

Advertisements