Programming Articles - Page 2527 of 3366

How can we set a background color to JSplitPane in Java?

Alshifa Hasnain
Updated on 23-Apr-2025 17:18:24

504 Views

In this article, we will learn to set a background color for JSplitPane in Java. JSplitPane is a Swing component that divides two (or more) components with a resizable divider. By default, JSplitPane does not directly support background color changes due to its complex structure. What is a 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. Syntax The following is the syntax for a JSplitPane initialization: JSplitPane ... Read More

How to implement the search functionality of a JTable in Java?

raja
Updated on 10-Feb-2020 10:57:34

3K+ Views

A JTable is a subclass of JComponent for displaying complex data structures. A JTable component can follow the Model View Controller (MVC) design pattern for displaying the data in rows and columns. A JTable can generate TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener, RowSorterListener interfaces. We can implement the search functionality of a JTable by input a string in the JTextField, it can search for a string available in a JTable. If the string matches it can only display the corresponding value in a JTable. We can use the DocumentListener interface of a JTextField to implement it.Exampleimport java.awt.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public ... Read More

How can we hide left/right pane of a JSplitPane programmatically in Java?

Alshifa Hasnain
Updated on 15-May-2025 19:38:41

533 Views

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

C Program for Egg Dropping Puzzle - DP-11?

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

367 Views

This is a famous puzzle problem. Suppose there is a building with n floors, if we have m eggs, then how can we find the minimum number of drops needed to find a floor from which it is safe to drop an egg without breaking it.There some important points to remember −When an egg does not break from a given floor, then it will not break for any lower floor also.If an egg breaks from a given floor, then it will break for all upper floors.When an egg breaks, it must be discarded, otherwise we can use it again.Input - The ... Read More

C Program for Basic Euclidean algorithms?

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

274 Views

Here we will see the Euclidean algorithm to find the GCD of two numbers. The GCD (Greatest Common Divisor) can easily be found using Euclidean algorithm. There are two different approach. One is iterative, another one is recursive. Here we are going to use the recursive Euclidean algorithm.AlgorithmEuclideanAlgorithm(a, b)begin    if a is 0, then       return b    end if    return gcd(b mod a, a) endExample Live Demo#include using namespace std; int euclideanAlgorithm(int a, int b) {    if (a == 0)       return b;    return euclideanAlgorithm(b%a, a); } main() {    int a, b;    cout > a >> b;    cout

C/C++ Program for Largest Sum Contiguous Subarray?

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

471 Views

An array of integers is given. We have to find sum of all elements which are contiguous. Whose sum is largest, that will be sent as output.Using dynamic programming we will store the maximum sum up to current term. It will help to find sum for contiguous elements in the array.Input: An array of integers. {-2, -3, 4, -1, -2, 1, 5, -3} Output: Maximum Sum of the Subarray is : 7AlgorithmmaxSum(array, n)Input − The main array, the size of the array.Output − maximum sum.Begin    tempMax := array[0]    currentMax = tempMax    for i := 1 to n-1, ... Read More

BFS using STL for competitive coding in C++?

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

689 Views

The Breadth First Search (BFS) traversal is an algorithm, which is used to visit all of the nodes of a given graph. In this traversal algorithm one node is selected and then all of the adjacent nodes are visited one by one. After completing all of the adjacent vertices, it moves further to check another vertices and checks its adjacent vertices again.In The competitive coding, we have to solve problems very quickly. We will use the STL (Standard Library of C++) to implement this algorithm, we need to use the Queue data structure. All the adjacent vertices are added into ... Read More

atan() function for complex number in C++?

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

176 Views

Here we will see the atan() method for the complex numbers. The complex numbers can be used using complex header file. In that header file the atan() function is also present. This is complex version of normal atan() function. This is used to find complex arc tan of a complex number.This function takes a complex number as input parameter, and returns the arc tan as output. Let us see one example to get the idea.Example Live Demo#include #include using namespace std; int main() {    complex c1(5, 2);    //atan() function for complex number    cout

asin() function for complex number in C++?

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

177 Views

Here we will see the asin() method for the complex numbers. The complex numbers can be used using complex header file. In that header file the asin () function is also present. This is complex version of normal asin () function. This is used to find complex arc sine of a complex number.This function takes a complex number as input parameter, and returns the arc sine as output. Let us see one example to get the idea.Example Live Demo#include #include using namespace std; int main() {    complex c1(5, 2);    //asin() function for complex number    cout

Arithmetic Mean in c++?

Ravi Ranjan
Updated on 25-Jul-2025 17:07:37

2K+ Views

An arithmetic mean is the average of all the given numbers, which is calculated by summing all the numbers and dividing this calculated sum by the total number of elements. The formula for calculating the arithmetic mean is: $$ \bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i = \frac{x_1 + x_2 + x_3 + \cdots + x_n}{n} $$ Here, we are given an array of integers and our task is to calculate the arithmetic mean of these numbers using the above formula: Scenario 1 Input: num = 2, 7, 4, ... Read More

Advertisements