Arjun Thakur has Published 1025 Articles

Java Program to retrieve the value from a cell in a JTable

Arjun Thakur

Arjun Thakur

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

1K+ Views

To retrieve the value of a cell, use the getValueAt() method. As parameters, set the row and column index value for which you want the cell value −int rIndex = 5; // row index int cIndex = 1; // column index Object ob = table.getValueAt(rIndex, cIndex);Display the cell value in ... Read More

Java program to set the color of a single tab’s text in a JTabbedPane Container

Arjun Thakur

Arjun Thakur

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

487 Views

To set the the color of a single tab’s text, use the setForegroundAt() method. This gives an option to mention the index and the color. The index here is the index of the specific tab you want to color the text.Let us first create a JTabbedPane −JTabbedPane tabbedPane = new ... Read More

Can we use {} while creating a MySQL table?

Arjun Thakur

Arjun Thakur

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

201 Views

No, you need to use open and close parenthesis like this ( ) while creating a table. Use the below syntax −CREATE TABLE IF NOT EXISTS yourTableName (    yourColumnName1 dataType1,    .    .    .    .    .    N );Let us first create a table −mysql> ... Read More

How to set the content of the label to be right-justified and top-aligned in Java?

Arjun Thakur

Arjun Thakur

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

134 Views

To set the text of the label component to be right-justified and top-aligned, you need to set the alignment. Set the label to be on the right and top aligned −JLabel label = new JLabel("Fav Sports", JLabel.RIGHT); label.setVerticalAlignment(JLabel.TOP);Here, we have set the size of the label as well as the ... Read More

How to set font for text in JTextPane with Java?

Arjun Thakur

Arjun Thakur

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

1K+ Views

Use the Font class to set font for text. Let us first create JTextPane component −JTextPane textPane = new JTextPane();Now, set the font with the Font class setFont() method −Font font = new Font("Serif", Font.ITALIC, 18); textPane.setFont(font);The following is an example to set font for text −Examplepackage my; import java.awt.BorderLayout; ... Read More

MySQL query to insert current date plus specific time?

Arjun Thakur

Arjun Thakur

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

451 Views

You can use CONCAT() for this. The syntax is as follows −insert into DemoTable values(concat(curdate(), ' yourSpecificTime’));Let us first create a table −mysql> create table DemoTable    (    ArrivalDate datetime    ); Query OK, 0 rows affected (1.06 sec)Insert some records in the table using insert command. We are ... Read More

How to create a border with a lowered beveled edge in Java?

Arjun Thakur

Arjun Thakur

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

275 Views

Use the createLoweredBevelBorder() method to create a border with a lowered beveled edge. We will set it on the label component −JLabel label; label = new JLabel("This has a border with a lowered bevel edge!"); label.setBorder(BorderFactory.createLoweredBevelBorder());The following is an example to create a border with a lowered beveled edge −Examplepackage ... Read More

How can I create a dialog box in Java with Yes No and cancel buttons?

Arjun Thakur

Arjun Thakur

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

2K+ Views

For a dialog box with Yes No Cancel buttons, you need to use the JOptionPane.showConfirmDialog(), wherein you will get a confirmation dialog box.The following is an example to create a dialog box in Java with Yes No and cancel buttons −Examplepackage my; import java.awt.Dimension; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JOptionPane; ... Read More

How to get the Tab Size of a JTextArea in Java?

Arjun Thakur

Arjun Thakur

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

365 Views

To get the tab size from a JTextArea, you can use the getTabSize() method −textArea.getTabSize();We will assign it to int variable and display the size in the Console −int size = textArea.getTabSize(); System.out.println("Tab Size = "+size);The following is an example to set the tab size of a JTextArea −Examplepackage my; ... Read More

How can I update a field in a MySQL database table by adding a value in the second table with a value from the first table?

Arjun Thakur

Arjun Thakur

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

127 Views

Let us first create a table −mysql> create table DemoTable1    (    value int    ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(10); Query OK, 1 row affected (0.17 sec)Display all records from the table using ... Read More

Advertisements