Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2610 of 3366
242 Views
To set a spinner of dates, at first create a date object −Date today = new Date();Now, use SpinnerDateModel −JSpinner spinner2 = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH));We will now consider a DateEditor, which is an editor for a JSpinner whose model is a SpinnerDateModel. Set the format for month here −JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner2, "MM"); spinner2.setEditor(editor);The following is an example to set a spinner of date in Java −Examplepackage my; import java.awt.GridBagLayout; import java.util.Calendar; import java.util.Date; import javax.swing.*; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame("Spinner Demo"); ... Read More
300 Views
Minor Tick marks is the number passed in representing the distance between each minor tick mark. For example, a slider with range from 0 to 70 and minor tick spacing 10, would give minor ticks next to the following values: 0, 10, 20, 30, 40, 50, 60, 70.To set minor tick marks, use the setMinorTickSpacing() method −JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 60); slider.setMinorTickSpacing(10);Note − For minor ticks to be painted, you need to set setPaintTicks to true.The following is an example to set minor tick marks in a slider every 10 units −Examplepackage my; import javax.swing.JFrame; import javax.swing.JPanel; ... Read More
382 Views
In this article, we will learn how to add a component to a JTextPane in Java. By using StyledDocument and StyleConstants, we can insert elements like buttons within the text pane, allowing us to create dynamic and interactive text-based components.JTextPaneJTextPane is a versatile text component in Java Swing that allows for styled text. It supports multiple text formats like bold, italic, and different fonts. It can also display rich text, such as embedded images or buttons, through the StyledDocument class. Inserting a component into a JTextPane The following are the steps to insert a component into a JTextPane − ... Read More
692 Views
In this article, we will learn to remove the last row from a table with DefaultTableModel in Java. Managing table data dynamically is a common requirement when working with Java Swing applications. One such operation is removing the last row from a JTable using DefaultTableModel. Understanding DefaultTableModel in Java DefaultTableModel is a flexible table model in Java's Swing library that allows developers to dynamically manage table data, including adding and removing rows and columns. Provides built-in methods for adding and removing rows easily. Approach to Removing the Last Row In this program, we create a table with multiple rows and ... Read More
416 Views
Memory cycleRegardless of the programming language, the memory cycle is almost same for any programming language. There are 3 steps in a memory life cycle1) Allocation of memory .2) use the allocated memory(reading or writing)3) Release the allocated memory when it is unnecessary.The first and last parts are directly connected in low-level languages but are indirectly connected in high-level languages such as JavaScript.1) Allocation of memory in javascriptJavaScript is called garbage collected language, that is when variables are declared, it will automatically allocate memory to them.When there are no more references for the declared variables, allocated memory will be released. ExampleIn the ... Read More
1K+ Views
To add empty border, use the createEmtyBorder() method. Let us first create a new JLabel −JLabel label; label = new JLabel("Label with empty border!");Now, set empty border using the setBorder() method −label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));The following is an example to add empty border to JPanel −Examplepackage my; import javax.swing.BorderFactory; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Demo"); JLabel label; label = new JLabel("Label with empty border!"); label.setFont(new Font("Verdana", Font.PLAIN, 16)); ... Read More
1K+ Views
To set the background color of a single tab, use the setBackgroundAt() 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.Let us first create a JTabbedPane −JTabbedPane tabbedPane = new JTabbedPane();Now, set the background color for one of the tabs with index 2 −tabbedPane.setBackgroundAt(2, Color.RED);The following is an example to set the background color of a single tab in a JTabbedPane container −Examplepackage my; import javax.swing.*; import java.awt.*; public class SwingDemo { public static void main(String args[]) { JFrame ... Read More
282 Views
To highlight multiple rows in a table, you can use the addRowSelectionInterval() method. At first create a table −DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel);Add some columns −tableModel.addColumn("Language/ Technology"); tableModel.addColumn("Text Tutorial"); tableModel.addColumn("Video Tutorial"); tableModel.addColumn("Views");Now, add rows to the table −tableModel.addRow(new Object[] { "NodeJS", "No", "Yes", "2350"}); tableModel.addRow(new Object[] { "MVC", "Yes", "No", "1500"}); tableModel.addRow(new Object[] { "ASP.NET", "Yes", "Yes", "3400"}); tableModel.addRow(new Object[] { "F#", "Yes", "No", "7890"}); tableModel.addRow(new Object[] { "Blockchain", "Yes", "No", "10600"}); tableModel.addRow(new Object[] { "SharePoint", "Yes", "Yes", "4900"});Highlight multiple rows by adding interval of rows from both ends. Set interval (index) for both the ... Read More
710 Views
Let’s say the following is our JTextPane with orange background color −JTextPane textPane = new JTextPane(); textPane.setBackground(Color.orange);Now, set the style and attributes. Also, set the font −SimpleAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setItalic(attributeSet, true); textPane.setCharacterAttributes(attributeSet, true); textPane.setText("Recall this and "); Font font = new Font("Verdana", Font.BOLD, 22); textPane.setFont(font);After the text displayed above, we will insert an image using setIcon() −StyledDocument doc = (StyledDocument) textPane.getDocument(); Style style = doc.addStyle("StyleName", null); StyleConstants.setIcon(style, new ImageIcon("E:\kind.png")); doc.insertString(doc.getLength(), "invisible text", style);The following is an example to insert an image into a component. Here, we have inserted an image into a JTextPane component −Examplepackage my; import ... Read More
34K+ Views
Yes, It is possible to have a try block without a catch block by using a final block. As we know, a final block will always execute even there is an exception occurred in a try block, except System.exit() it will execute always. Example 1 public class TryBlockWithoutCatch { public static void main(String[] args) { try { System.out.println("Try Block"); } finally { System.out.println("Finally Block"); } } } Output Try Block Finally Block A ... Read More