In this article, we will learn how to limit the number of characters inside a JTextField in Java. Whether you're creating a form for phone numbers, zip codes, or usernames, controlling the maximum number of characters is important for data validation. JTextField A JTextField is one of the most important Swing components that allows the user to an input text value in a single line format. We can restrict the number of characters that the user can enter into a JTextField can be achieved by using the PlainDocument class. PlainDocument Class PlainDocument is a subclass that extends the AbstractDocument, a ... Read More
In this article, we will learn to read an input value from a JTextField and add it to a JList in Java. The Swing's two commonly used components are JTextField for text input and JList for displaying a list of items for building graphical user interfaces. JList A JList is a subclass of the JComponent class that allows the user to choose either a single selection or multiple selections. The JList class itself does not support a scrollbar. In order to add a scrollbar, we have to use the JScrollPane class together with the JList class. The JScrollPane then manages ... Read More
In this article, we will learn how to hide the left/right pane of a JSplitPane programmatically in Java. JSplitPane is a simple Swing component in GUI programming that allows hiding one side of the split pane, resulting in a collapsible panel look. JSplitPane A JSplitPane is a subclass of the JComponent class that allows us to arrange two components side by side horizontally or vertically in a single pane. The display areas of both components can also be adjusted at runtime by the user. The important methods of JSplitPane are remove(), removeAll(), resetToPreferredSizes(), and setDividerLocation(). A JSplitPane can generate a ... Read More
JavaScript like other programming languages, permits whitespace and line breaks to make the code more readable. Although JavaScript tends to ignore whitespace, line breaks at times influence the way in which the code is presented. What is Whitespace in JavaScript? Whitespace in JavaScript comprises newlines, tabs, and spaces. JavaScript's engine disregards excess whitespace, i.e., inserting spaces between variables, operators, or keywords doesn't influence the code's execution. Example For example, the following two code snippets are functionally identical − var employee = "Amit"; var employee="Amit"; Even though the first example has spaces around the assignment operator (=), JavaScript treats both lines the ... Read More
Two commonly used functions from the Python time module are time.time() and time.clock(). Each function provides a different purpose and returns different values depending on the platform (Windows vs. Unix). In Python 3.8, time.clock() was removed, so time.perf_counter() or time.process_time() are generally preferred over the older time.clock() for specific CPU time measurements. The time.clock() was designed for measuring process CPU time, while time.time() measures wall-clock time. The time.time() is more accurate for measuring overall elapsed time ( the duration of time that has passed between two specific points in time). Measuring Elapsed Time with time.time() The time.time() function returns the number of ... Read More
In this article, we will learn to add a new list element under a "" using jQuery. jQuery is a popular JavaScript library that simplifies HTML manipulation, event handling, and animations. One of its practical applications is dynamically adding elements to a webpage without requiring a full page reload. Why Use jQuery? DOM (Document Object Model) updating using basic JavaScript might become difficult and needs more than one line of code. jQuery has simplified it through easy selectors and functions. Employing jQuery helps us − Select elements efficiently. Handle events seamlessly. ... Read More
Binary Tree traversal is a process of visiting all the nodes in a certain order. In this article, we will learn how to perform inorder non-recursive traversal of a binary tree using a stack in C++. What is Inorder Non-Recursive Traversal? Inorder traversal is a type of tree traversal, where we first visit the left subtree, then the root node, and then the right subtree. In a non-recursive approach, we are not allowed to use recursive functions to track nodes for traversing the tree. Instead, we can use an explicit stack data structure to track nodes and traverse through ... Read More
A dictionary is a collection of key-value pairs where, keys are unique and used to identify corresponding values in the dictionary. In this article, we will learn how to perform dictionary operations such as insertion, search, and traversal using a binary search tree (BST) in C++. What is BST? A binary search tree (BST) is a tree data structure, where each node has at most two children and follows two rules: the left subtree contains keys less than the node’s key, and the right subtree contains keys greater than the node’s key. This structure is same as how a ... Read More
To print the size of an array parameter in a function in C++, we will use the typeOf() operator. In this article, we have passed an array as an argument to the function. Our task is to print the size of this array in C++. Printing Size of Static Array Parameter When we pass an array as an argument of function in C++, it is considered as a pointer. The sizeOf() operator returns the size of the pointer, depending on the system(64-bit or 32-bit) rather than returning the size of the array. Here is a code example explaining this. ... Read More
The lifetime of a static variable in a C++ function exists till the program executes. We can say the lifetime of a static variable is the lifetime of the program. The static variable is a variable that is declared using the static keyword. The space for the static variable is allocated only one time, and this is used for the entirety of the program. In this article, we will understand the lifetime of the static variable and the reason behind its lifetime. Why do Static Variable Exists until program execution? A static variable is initialized ... Read More