Arjun Thakur has Published 1109 Articles

How to set font for text in JTextPane with Java?

Arjun Thakur

Arjun Thakur

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

931 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

344 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

182 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

1K+ 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

199 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

62 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

Python program to Rearrange a string so that all same characters become d distance away

Arjun Thakur

Arjun Thakur

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

825 Views

Given a non-empty string str and an integer k , rearrange the string such that the same characters are at least distance k from each other.All input strings are given in lowercase letters. If it is not possible to rearrange the string, return an empty string "".Example 1:str = “tutorialspoint”, k = 3 Answer: “tiotiotalnprsu”The same ... Read More

How to add a tooltip to a component in Java?

Arjun Thakur

Arjun Thakur

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

370 Views

Let us first create a component −JLabel label1; label1 = new JLabel("Id", SwingConstants.CENTER); Now, set the tooltip for the above component − label1.setToolTipText("Enter Id");ExampleThe following is an example to add a tooltip to a component in Java −package my; import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JLabel; import ... Read More

How to set the titled justification (position title text) of the titled border in Java

Arjun Thakur

Arjun Thakur

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

270 Views

To set the titled justification of the titled border, use the setTitleJustification() method. The following is an example to set the title justification of the titled border −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; public class SwingDemo {   ... Read More

How to set raised and lowered SoftBevelBorder for components in Java. Also set the border color.

Arjun Thakur

Arjun Thakur

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

90 Views

Let us see how to set the raised SoftBevelBorder −Border raisedBorder = new SoftBevelBorder(    SoftBevelBorder.RAISED, Color.GREEN, Color.GREEN.darker(), Color.MAGENTA, Color.magenta.brighter());Let us see how to set the lowered SoftBevelBorder −Border loweredBorder = new SoftBevelBorder(    SoftBevelBorder.LOWERED, Color.ORANGE, Color.YELLOW.darker(), Color.BLUE, Color.yellow.brighter());The following is an example to set raised and lowered SoftBevelBorder for ... Read More

Advertisements