Ankith Reddy has Published 1070 Articles

Set the location of component in a GridBagLayout with Java

Ankith Reddy

Ankith Reddy

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

389 Views

To set the location of component, use the GridBagConstraints. Here, we have two components −GridBagConstraints gbc = new GridBagConstraints(); JLabel label = new JLabel("Email-Id − "); JTextArea text = new JTextArea(); text.setText("Add id here...");Set the location with gridx and gridy −gbc.gridx = 0; gbc.gridy = 0; layout.setConstraints(label, gbc); panel.add(label);The following ... Read More

Can we update a row with the highest ID in a single MySQL query?

Ankith Reddy

Ankith Reddy

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

182 Views

Yes, we can do that. Let us first create a table −mysql> create table DemoTable    (    ID int,    GameScore int    ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(15, 848747); Query OK, 1 row ... Read More

Java Program to enable column selection in a JTable

Ankith Reddy

Ankith Reddy

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

166 Views

To enable colum selection, use the setColumnSelectionAllowed() method and set it to TRUE −table.setCell setColumnSelectionAllowed(true);The following is an example to enable column selection in a table −Examplepackage my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void ... Read More

How to check whether now() falls between two specific dates in MySQL?

Ankith Reddy

Ankith Reddy

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

398 Views

Here, now() represents the current date. To check whether it falls between two specific dates, you need to use the BETWEEN. Let us first create a table −mysql> create table DemoTable    (    FirstDate datetime,    SecondDate datetime    ); Query OK, 0 rows affected (0.60 sec)Insert some records ... Read More

How to generate field in MySQL SELECT?

Ankith Reddy

Ankith Reddy

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

128 Views

Use keyword AS for this. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(20)    ); Query OK, 0 rows affected (3.16 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('John'); ... Read More

Can we set JOptionPane with predefined selection in Java?

Ankith Reddy

Ankith Reddy

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

124 Views

For predefined selection, use the setSelectedIndex() method, wherein you need to set the index of the item you want to be visible first.Let’s say the following is our aComboBox with elements −Object[] sports = { "Football", "Cricket", "Squash", "Baseball", "Fencing", "Volleyball", "Basketball" }; JComboBox comboBox = new JComboBox(sports);Now, set the ... Read More

MySQL query to find all rows where ID is divisible by 4?

Ankith Reddy

Ankith Reddy

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

389 Views

Let us first create a table with one of the column as ID −mysql> create table DemoTable    (    ID int,    StudentName varchar(10),    CountryName varchar(20)    ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(0, ... Read More

Get the count of the most frequently occurring values in MySQL?

Ankith Reddy

Ankith Reddy

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

1K+ Views

For this, use the aggregate function COUNT() along with GROUP BY. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value int    ); Query OK, 0 rows affected (0.74 sec)Insert some records in the table using insert ... Read More

Display multiple lines of text in a component’s tooltip with Java

Ankith Reddy

Ankith Reddy

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

535 Views

Let’s first see how we set text in a components tooltip −JLabel label3 = new JLabel("Password", SwingConstants.CENTER); label3.setToolTipText("Enter Password");To display multiple lines of text in a tooltip, use . Here, we have used the HTML tag for new line and that would create multiple lines of text in the ... Read More

Packing and Unpacking Arguments in Python?

Ankith Reddy

Ankith Reddy

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

869 Views

If you have done little-bit of programming in python, you have seen the word “**args” and “**kwargs” in python functions. But what exactly they are?The * and ** operators did different operations which are complementary to each other depending on where we are using them.So when we are using them ... Read More

Advertisements