How to hide and display JCombobox with a JCheckBox in Java?

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

384 Views

To toggle visibility with JCheckBox, use isVisible() method:JCheckBox toggleVisibility = new JCheckBox("Hide/Show"); toggleVisibility.setSelected(comboBox.isVisible()); toggleVisibility.addItemListener(e -> {    comboBox.setVisible(e.getStateChange() == ItemEvent.SELECTED); });The following is an example to hide and display JCombobox with a JCheckBox in Java:Exampleimport java.awt.BorderLayout; import java.awt.event.ItemEvent; import javax.swing.*; public class SwingDemo {    JFrame frame;    SwingDemo(){       frame = new JFrame("ComboBox");       String Sports[]={"Select", "Tennis", "Cricket", "Football"};       JComboBox comboBox = new JComboBox(Sports);       comboBox.setBounds(50, 50, 90, 20);       frame.add(comboBox, BorderLayout.CENTER);       JCheckBox toggleVisibility = new JCheckBox("Hide/Show");       toggleVisibility.setSelected(comboBox.isVisible());       toggleVisibility.addItemListener(e ... Read More

Java DatabaseMetaData supportsGroupBy() method with example

Rishi Raj
Updated on 30-Jul-2019 22:30:26

31 Views

The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups. This GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause.SyntaxThe basic syntax of a GROUP BY clause is shown in the following code block. The GROUP BY clause must follow the conditions in the WHERE clause and must precede the ORDER BY clause if one is used.SELECT column1, column2 FROM table_name WHERE [ conditions ] GROUP BY column1, column2 ORDER BY column1, column2The supportsGroupBy() method of the DatabaseMetaData interface is used to determine whether ... Read More

Explain about add and assignment(+=) operator in detail in javascript?

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

117 Views

add and assignment(+=) operatorThe add and assignment(+=) operator reduces the code little bit.It may not much influential  in small codes whereas coming to long codes it's use can't be ignored. Live DemoExample    var tot = 0;    var a = [1,45,78,9,78,40];    for(var i = 0; i

IPC through shared memory

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

3K+ Views

Shared memory is a memory shared between two or more processes. However, why do we need to share memory or some other means of communication?To reiterate, each process has its own address space, if any process wants to communicate with some information from its own address space to other processes, then it is only possible with IPC (inter process communication) techniques. As we are already aware, communication can be between related or unrelated processes.Usually, inter-related process communication is performed using Pipes or Named Pipes. Unrelated processes (say one process running in one terminal and another process in another terminal) communication ... Read More

How to right-align a menu in the menu bar with Java?

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

717 Views

Let’s say we added a menu to the MenuBar −JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);Add the glue component in between the menus to align some of them on the right, for example −menuBar.add(Box.createHorizontalGlue());The menu added after the usage of above method, would get right-aligned −JMenu sourceMenu = new JMenu("Source"); sourceMenu.setMnemonic(KeyEvent.VK_S); menuBar.add(sourceMenu);The following is an example to right-align a menu in the menu bar with Java −Examplepackage my; import java.awt.event.KeyEvent; import javax.swing.Box; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class SwingDemo {    public static void main(final String args[]) {       ... Read More

How to insert mm/dd/yyyy format dates in MySQL?

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

4K+ Views

For this, use STR_TO_DATE(). Following is the syntax −insert into yourTableName values(STR_TO_DATE(yourDateValue, yourFormatSpecifier));Let us first create a table −mysql> create table DemoTable    (    ShippingDate date    ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command : Here, we are inserting formatted dates using date formats like m, d, y, etc −mysql> insert into DemoTable values(STR_TO_DATE('06-01-2019', '%m-%d-%Y')); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(STR_TO_DATE('01-31-2019', '%m-%d-%Y')); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(STR_TO_DATE('02-01-2018', '%m-%d-%Y')); Query OK, 1 row affected (0.27 sec)Display all records ... Read More

Removing an element from C++ std::vector<> by index?

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

246 Views

Remove an element from C++ std::vector by index can be done by following way −Example Live Demo#include #include using namespace std; int main() {    vector v; //declare vector    //insert elements into vector    v.push_back(-10);    v.push_back(7);    v.push_back(6);    // Deletes the first element (v[0])    v.erase(v.begin() );    for (int i = 0; i < v.size(); i++)       cout

What will happen when we try to override final method of the superclass in Java?

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

1K+ Views

Any method that is declared as final in the superclass cannot be overridden by a subclass. If we try to override the final method of super class we will get an error in Java.Rules for implementing Method OverridingThe method declaration should be the same as that of the method that is to be overridden.The class (subclass) should extend another class (superclass), prior to even try overriding.The Sub Class can never override final methods of the Super Class.ExampleLive Democlass Car {    public void brake() {       System.out.println("brake() method of Car");    }    public final void accelerate() {       ... Read More

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

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

973 Views

_isEqual() _isEqual() is from the underscore and lodash library of javascript. It is used to compare javascript objects. The importance of this method is that it doesn't care about the order of properties while comparing the objects. It only checks whether the properties in the two objects are equal or not. Whereas JSON.stringify(), which is used in comparing the objects, checks even the order of properties of the objects, making _isEqual() the better option. syntax_.isEqual(object1, object2);It accepts two objects as parameters and scrutinizes whether they are equal or not.ExampleLive Demo    var obj1 = {name: "Sikha", designation: "Content developer"}; ... Read More

How to combine two tables and add a new column with records in MySQL?

Rama Giri
Updated on 30-Jul-2019 22:30:26

439 Views

Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(100)    -> ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(Name) values('Chris'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1(Name) values('Robert'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;Output+----+--------+ | Id | Name   | +----+--------+ |  1 | Chris  | |  2 | Robert | +----+--------+ 2 ... Read More

Advertisements