Ankith Reddy has Published 1070 Articles

How to create two borders for a single component in Java?

Ankith Reddy

Ankith Reddy

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

247 Views

To create two borders for a single component, use the createCompoundBorder() method in Java. Here, we have created LineBorder nd TitledBorder −LineBorder lineBorder = new LineBorder(Color.red); TitledBorder titleBorder = new TitledBorder("Demo Title"); Border border = BorderFactory.createCompoundBorder(lineBorder, titleBorder);Now, set both the borders for a single component −JButton button = new JButton("two ... Read More

How to enable Scrolling Tabs in a JTabbedPane Container

Ankith Reddy

Ankith Reddy

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

213 Views

To enable scrolling tabs in a JTabbedPane container, use the setTabLayoutPolicy() method −tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);Above, we have set the constant to be SCROLL_TAB_LAYOUT, since we want the scroller to be visible when all the tabs won’t fit within a single run.The following is an example to enable scrolling tabs in a JTabbedPane ... Read More

Get rows with GROUP BY in MySQL?

Ankith Reddy

Ankith Reddy

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

171 Views

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

Set the content of the JLabel to be left-justified and top-aligned in Java

Ankith Reddy

Ankith Reddy

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

398 Views

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

How to create a compound border for a component in Java?

Ankith Reddy

Ankith Reddy

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

433 Views

Composed border consists of two or more borders i.e. border around a border. We can create it for a component in Java using the createCompoundBorder() method.Let’s say the following is our component −JLabel label; label = new JLabel("This has compound border (border around a border)!");Now, set the compound border −label.setBorder(BorderFactory.createCompoundBorder(BorderFactory ... Read More

Update all rows by prefixing a line to every text in MySQL?

Ankith Reddy

Ankith Reddy

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

253 Views

For this, use the CONCAT() function. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Subject varchar(200)    ); Query OK, 0 rows affected (1.36 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Subject) ... Read More

How to delete '\' entry in MySQL?

Ankith Reddy

Ankith Reddy

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

68 Views

You can use delete command −delete from yourTableName where yourColumnName='\\';Let us first create a table −mysql> create table DemoTable    (    FolderName varchar(100)    ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values("????"); Query OK, 1 row ... Read More

Java Program to remove the first row from a table with DefaultTableModel

Ankith Reddy

Ankith Reddy

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

532 Views

To remove the first row from a table, use the removeRow() method and set its parameter to 0 since you need to remove the first row i.e. index 0.Let us first see an example to display a table with rows and columns. The table here has 9 rows −Examplepackage my; ... Read More

Can we change the Cursor with Java Swing?

Ankith Reddy

Ankith Reddy

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

927 Views

Yes, we can change the default cursor representation in Java. Let us first create a button component −JButton button = new JButton("Button with two borders");Whenever user will keep the mouse cursor on the above button component, the cursor would change to hand cursor −Cursor cursor = button.getCursor(); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));The following is ... Read More

Delete all rows except only a specific row in MySQL?

Ankith Reddy

Ankith Reddy

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

989 Views

To delete all rows except a single specific row, try the below syntax −delete from yourTableName where yourColumnName!=yourValue;Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Subject varchar(100)    ); Query OK, 0 rows affected (0.65 sec)Insert some ... Read More

Advertisements