George John has Published 1167 Articles

How can we change the default font of the JTabbedPane tabs in Java?

George John

George John

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

293 Views

To display the default font of the tabs, you need to use the Font class. Let’s say we created a JTabbedPane in Java −JTabbedPane tabbedPane = new JTabbedPane();Now, set the Font with font face, style and font size −Font font = new Font("Arial", Font.CENTER_BASELINE, 20); tabbedPane.setFont(font);The following is an example ... Read More

MySQL query to convert a string into a month (Number)?

George John

George John

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

172 Views

Use the str_to_date() method −select month(str_to_date(yourColumnName, '%b')) from yourTableName;Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    MonthName varchar(100)    ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert ... Read More

Java Program to increase the row height in a JTable

George John

George John

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

990 Views

To increase the row height, use the setRowHeight() method for a table in Java. Row height is the height of the row in pixels.Let’s say the following is our table −DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel);Set the rows and columns and increase the row height by ... Read More

Java Program to count the child of root node in a JTree

George John

George John

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

191 Views

Use the getChildCount() method to count the number of root node in a JTree. Here, our root node is “node”. Therefore to count its child node, use −System.out.println("Number of children of node = " + node.getChildCount());We have displayed the count in the Console as shown above. The following is an ... Read More

How to disable a MenuItem in Java?

George John

George John

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

1K+ Views

To disable a MenuItem, use the setEnabled() method and set it to FALSE. Let’s say we have the following MenuBar −JMenuBar menuBar = new JMenuBar();Now, create a Menu −JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);We will now create two MenuItems inside the above Menu −JMenuItem menuItem1 = new JMenuItem("New", KeyEvent.VK_N); ... Read More

MySQL query to select date >= current date - 3 weeks?

George John

George John

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

677 Views

Use the concept of DATE_SUB(). Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ArrivalDate datetime    ); Query OK, 0 rows affected (1.02 sec)Note: Let’s say the current date is 2019-06-08Insert some records in the table using ... Read More

Select specific rows in a range with MySQL?

George John

George John

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

453 Views

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

How to make JTable single selectable in Java?

George John

George John

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

213 Views

To make JTable single selectable in Java, you need to set the selection mode to be SINGE_SELECTION. Let’s say the following is our table −String[][] rec = {    { "001", "Shirts", "40" },    { "002", "Trousers", "250" },    { "003", "Jeans", "25" },    { "004", "Applicances", ... Read More

How to create a vertical toolbar in Java?

George John

George John

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

327 Views

Let us first create a toolbar −JToolBar toolbar = new JToolBar();Now, set the orientation to create vertical toolbar −toolbar.setOrientation(SwingConstants.VERTICAL);The following is an example to create a vertical toolbar in Java −package my; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JToolBar; import javax.swing.SwingConstants; public class SwingDemo {    public ... Read More

How to add a title to an existing line border in Java?

George John

George John

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

249 Views

Here, we will see how to add a title to an existing Line border. Let’s say we have a label and the border is to be set −LineBorder linedBorder = new LineBorder(Color.blue); TitledBorder titledBorder = BorderFactory.createTitledBorder(linedBorder, "Demo Title"); JLabel label = new JLabel(); label.setBorder(titledBorder);The following is an example to add ... Read More

Advertisements