Arjun Thakur has Published 1109 Articles

Can we hide the table header from a JTable in Java?

Arjun Thakur

Arjun Thakur

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

541 Views

Yes, we can hide the header from a table. Use the setTableHeader() method and set it to null -table.setTableHeader(null);Above, the table is our JTable -JTable table = new JTable(marks, col)The following is an example to hide the table header -Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import ... Read More

Returning Multiple Values in Python?

Arjun Thakur

Arjun Thakur

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

6K+ Views

Python functions can return multiple values. These values can be stored in variables directly. A function is not restricted to return a variable, it can return zero, one, two or more values.This is the default property of python to return multiple values/variables which is not available in many other programming ... Read More

How to create a Titleless and Borderless JFrame in Java?

Arjun Thakur

Arjun Thakur

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

487 Views

To create a Titleless and Borderless JFrame, use the setUndecorated() method and set it to TRUE −JFrame frame = new JFrame("Register!"); frame.setUndecorated(true);The following is an example to create a titleless and borderless JFrame −Examplepackage my; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo ... Read More

How to create and set an Empty Border from BorderFactory class in Java?

Arjun Thakur

Arjun Thakur

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

160 Views

To create and set empty border to a component, use the BorderFactory class createEmptyBorder() method −EmptyBorder emptyBorder = (EmptyBorder) BorderFactory.createEmptyBorder();To set the above border to a component, use the setBorder() method −JButton button = new JButton("Empty Border"); button.setBorder(emptyBorder);The following is an example to create and set and empty border from ... Read More

Java Program to display only horizontal grid lines in a JTable

Arjun Thakur

Arjun Thakur

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

96 Views

At first, set the setShowGrid() to FALSE to disable all the grid lines. To display only horizontal grid lines in a table, set the method setShowHorizontalLines() to TRUE. Let us first create a table with rows and columns −String[][] rec = {    { "1", "Steve", "AUS" },    { "2", ... Read More

How to disable auto resizing for a JTable in Java?

Arjun Thakur

Arjun Thakur

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

451 Views

To disable auto resizing for a table in Java, set the setAutoResizeMode() to AUTO_RESIZE_OFF −JTable table = new JTable(tableModel); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);The following is an example to disable auto resizing for a JTable in Java −package my; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public ... Read More

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

299 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

113 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

71 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

Advertisements