Java Program to disable the first item on a JComboBox

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

649 Views

To disable the first index, on the click of a button, let us implement for index > 0 i.e. item 2:System.out.println("Index 0 (First Item) is disabled... "); comboBox.addItemListener(e -> {    if (comboBox.getSelectedIndex() > 0) {       System.out.println("Index = " + comboBox.getSelectedIndex());    } });By implementing above, we have disabled the first item.The following is an example to disable the first item on a JComboBox:Exampleimport javax.swing.*; public class SwingDemo {    JFrame frame;    SwingDemo(){       frame = new JFrame("ComboBox");       String Sports[]={"Select", "Tennis", "Cricket", "Football"};       JComboBox comboBox = new JComboBox(Sports); ... Read More

Java DatabaseMetaData supportsResultSetType() method with example

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

81 Views

While creating a Statement object you can choose the concurrency and the type of the ResultSet object using the following variant of the createStatement() method −Statement createStatement(int resultSetType, int resultSetConcurrency)ResultSet ConcurrencyThe concurrency of the ResultSet object determines whether its contents can be updated or not.The ResultSet interface provides two values to specify the concurrency namely −CONCUR_READ_ONLY: If you set this as a value of the concurrency while creating the ResultSet object you cannot update the contents of the ResultSet you can only read/retrieve them.CONCUR_UPDATABLE: If you set this as a value of the concurrency while creating the ResultSet object you ... Read More

Explain about logical not(!) operator in detail with example in javascript?

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

93 Views

NOT operatorThe logical NOT operator gives true for false values and false for true values. Live DemoExample var x = 200; var y = 300; document.getElementById("logical").innerHTML = !(x < y) + "" + !(x > y); Outputfalse true

Designated Initializers in C

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

565 Views

In C90 standard we have to initialize the arrays in the fixed order, like initialize index at position 0, 1, 2 and so on. From C99 standard, they have introduced designated initializing feature in C. Here we can initialize elements in random order. Initialization can be done using the array index or structure members. This extension is not implemented in GNU C++.If we specify some index and put some value, then it will be look like this -int arr[6] = {[3] = 20, [5] = 40}; or int arr[6] = {[3]20, [5]40};This is equivalent to this:int arr[6] = {0, 0, ... Read More

How to set color to MatteBorder in Java?

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

138 Views

Set color to MatteBorder using the Color class −Border border = new MatteBorder(5, 10, 5, 5, Color.BLUE);Now, set it to a button component in Java −JButton button = new JButton("Matte Border"); button.setBorder(border);The following is an example to set color to MatteBorder in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; import javax.swing.border.MatteBorder; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED);       Border border = new MatteBorder(5, ... Read More

How to get day name from timestamp in MySQL?

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

217 Views

To get the day name from timestamp, use dayname() function −select dayname(yourColumnName) from yourTableName;    Let us first create a table :    mysql> create table DemoTable    (    LoginDate timestamp    ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-06-01'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2019-06-02'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-06-03'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('2019-06-04'); Query OK, 1 row affected (0.11 sec) mysql> insert into ... Read More

The best way to check if a file exists using standard C/C++

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

14K+ Views

The only way to check if a file exist is to try to open the file for reading or writing.Here is an example −In CExample#include int main() {    /* try to open file to read */    FILE *file;    if (file = fopen("a.txt", "r")) {       fclose(file);       printf("file exists");    } else {       printf("file doesn't exist");    } }Outputfile existsIn C++Example#include #include using namespace std; int main() {    /* try to open file to read */    ifstream ifile;    ifile.open("b.txt");    if(ifile) {       cout

Change Color of Button in iOS when Clicked

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

1K+ Views

Imagine you’re playing a song and as soon as you press the stop button, the color of the button should turn to red. This is one of the many scenario where you might need to change the color of button when it is clicked.In this tutorial we will see how to change the background color of a button when it is clicked. So let’s get started!Step 1 − Open Xcode → New Projecr → Single View Application → Let’s name it “ChangeButtonColor”Step 2 − In the Main.storyboard create one button and name it stop.Step 3 − Create @IBAction of the ... Read More

How to get the application name and version information of a browser in JavaScript?

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

2K+ Views

Javascript has provided a navigator object with which we can find any information regarding the browser. To get the application name and version information, navigator object has provided navigator.appName() and navigator.appVersion() respectively. Let's discuss each of them individually.Application Name of the browserTo get the application name, the navigator object has provided navigator.appName(). It may sound weird that "Netscape" is the application name for IE11, Chrome, Firefox, and Safari. So the output we get when we use navigator.appName() is Netscape.ExampleLive Demo document.write(navigator.appName); OutputNetscapeBrowser version informationTo get the browser version information, the navigator object has provided ... Read More

Add n binary strings in C++?

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

137 Views

Here we will see how we can write a program that can add n binary numbers given as strings. The easier method is by converting binary string to its decimal equivalent, then add them and convert into binary again. Here we will do the addition manually.We will use one helper function to add two binary strings. That function will be used for n-1 times for n different binary strings. The function will work like below.AlgorithmaddTwoBinary(bin1, bin2)begin    s := 0    result is an empty string now    i := length of bin1, and j := length of bin2   ... Read More

Advertisements