Customize the JOptionPane layout with updated color and image in Java

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

1K+ Views

Customize the layout by changing the look and feel of the panel in which you added the component −ImageIcon icon = new ImageIcon(new URL("http −//www.tutorialspoint.com/images/C-PLUS.png")); JLabel label = new JLabel(icon); JPanel panel = new JPanel(new GridBagLayout()); panel.add(label); panel.setOpaque(true); panel.setBackground(Color.ORANGE);Above, we have added an image and even updated the background color of the panel.Now, set it for the text panel −JPanel textPanel = new JPanel(new GridLayout(10, 5)); textPanel.setBackground(Color.Magenta);The following is an example to customize the JOptionPane layout −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; public class SwingDemo { ... Read More

MySQL select to count values equal to 0 and greater than 0 from a column?

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

739 Views

For this, use the CASE statement. Let us first create a table −mysql> create table DemoTable    (    Number int    ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.09 sec) mysql> insert ... Read More

What does immutable mean? Which Python types are mutable and which are not?

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

333 Views

In Python, there are two types of Objects.Mutable ObjectImmutable ObjectMutable: Mutable objects are modified, (i.e) objects are a changeable list, set, dict, etc are mutable.mutable objects are easy to change.Example 1list =["Tutorials ", "Point", "Pvt", "Ltd"] list[2]= 'Tutorix' listOutput['Tutorials ', 'Point', 'Tutorix', 'Ltd'] Example 2list=['Car', 'Bike', 'Scooty', 'Bus', 'Metro'] list[4]= 'Bicycle' listOutput['Car', 'Bike', 'Scooty', 'Bus', 'Bicycle'] Immutable: immutable objects are not modified (i.e) not changeable int, float, bool, str, tuple, Unicode, etc ... are immutable. immutable objects are expensive and difficult to change. a tuple is enclosed within the parenthesis tuples are immutable and can't be changed.Example 1tuple=('1', '2', 'Python', ... Read More

What is the importance of _without() method in JavaScript?

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

226 Views

_without() This method is in the underscore.js library of javascript. It takes two parameters and removes, what are the elements present in the second array, from the first array. It doesn't bother whether the values are true or false, it checks each value one by one and proceeds the task. Make sure that it is case sensitive.syntax_.without( array, values);ExampleIn the following example, it checks whether the values present in the second parameter are in the first parameter or not and tries to remove the available values. Live Demo    document.write(_.without([5, 6, 4, 8, 9, 9, 0, 1], 0, ... Read More

How to get the pixel depth and color depth of a screen in JavaScript?

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

449 Views

Javascript window object has provided many methods to get various kinds of information regarding the browser.  It has provided screen.colorDepth and screen.pixelDepth to get the color depth and pixel depth of browser screen respectively. Let's discuss them individually.Color depthThe window object has provided screen.colorDepth method to return the color depth. Color depth is nothing but the number of bits used to display one color. All modern computers use 24 bit or 32 bit hardware for color resolution.ExampleLive Demo document.getElementById("depth").innerHTML = "Screen color depth is " + screen.colorDepth; OutputScreen color depth ... Read More

c32rtomb() function in C/C++?

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

72 Views

In C++, we can use 32-bit character representations. The c32rtomb() function is used to convert 32-bit character representation to narrow multi-byte character representation. We can find this function inside the uchar.h header file.This function takes three parameters. These are −The string where multi-byte character will be stored32-bit character to convertThe pointer of type mbstate_t object. which is used to interpret multibyte string.This function returns number of bytes written to the character array, when it is successful, otherwise returns -1. Let us see an example to get better idea.Example Live Demo#include #include #include using namespace std; int main() { ... Read More

transform() in C++

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

2K+ Views

The transform function is present in the C++ STL. To use it, we have to include the algorithm header file. This is used to perform an operation on all elements. For an example if we want to perform square of each element of an array, and store it into other, then we can use the transform() function.The transform function works in two modes. These modes are −Unary operation modeBinary operation modeUnary Operation ModeIn this mode the function takes only one operator (or function) and convert into output.Example#include #include using namespace std; int square(int x) {    //define square ... Read More

Stringstream in C++

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

9K+ Views

Here we will see the string stream in C++. The string stream associates a string object with a string. Using this we can read from string as if it were a stream like cin.The Stringstream has different methods. These are like below −clear(): Used to clear the streamstr(): To get and set the string object whose content is present in streamoperator > : This is used to read from stringstream object.Let us see two examples of string streams. In the first program we will divide the words into separate strings.Example#include #include #include #include using namespace std; ... Read More

Java Connection getCatalog() method with example

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

682 Views

In general, a catalog is a directory which holds information about data sets, file or, a database. Whereas in a database catalog holds the list of all the databases, base tables, views (virtual tables), synonyms, value ranges, indexes, users, and user groups.The getCatalog() method of the Connection interface returns the name of the current catalog/database, of the current connection object.This method returns a Sting value representing the name of the catalog. It returns null if there is no catalog.To get the catalog name −Register the driver using the registerDriver() method of the DriverManager class as −//Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver());Get the connection ... Read More

Display distinctly ordered MongoDB record with skip and limit?

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

659 Views

You can work with aggregate framework and use $sort, $skip and $limit to display distinctly ordered records with skip and also set the limit. Let us first create a collection with documents> db.orderedDistinctDemo.insertOne({"Name":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8e0140b992277dae0e9") } > db.orderedDistinctDemo.insertOne({"Name":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8e5140b992277dae0ea") } > db.orderedDistinctDemo.insertOne({"Name":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8e7140b992277dae0eb") } > db.orderedDistinctDemo.insertOne({"Name":"Sam"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8ea140b992277dae0ec") } > db.orderedDistinctDemo.insertOne({"Name":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8ee140b992277dae0ed") } > db.orderedDistinctDemo.insertOne({"Name":"Carol"}); {    "acknowledged" : true,    "insertedId" ... Read More

Advertisements