Ankith Reddy has Published 996 Articles

How to create a Box Layout in Java?

Ankith Reddy

Ankith Reddy

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

3K+ Views

To create a Box Layout in Java Swing, use the BoxLayout class. Here, we have also set that the components should be laid our left to right or top to bottom −Box box = new Box(BoxLayout.X_AXIS); box.add(button1); box.add(button2); box.add(button3); box.add(button4); box.add(Box.createGlue()); box.add(button5); box.add(button6); box.add(button7); box.add(button8);Above, we have 8 buttons in ... Read More

MySQL query to decrease value by 10 for a specific value?

Ankith Reddy

Ankith Reddy

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

625 Views

Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Score int    ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score) values(67); Query OK, 1 row affected ... Read More

Set the location of component in a GridBagLayout with Java

Ankith Reddy

Ankith Reddy

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

501 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

269 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

228 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

493 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

175 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

237 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

543 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

Advertisements