
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
Found 33676 Articles for Programming

1K+ Views
To add JList to Scroll pane in Java, use JScrollPane:JList list = new JList(sports); JScrollPane scrollPane = new JScrollPane(list);After that set it to Container:Container contentPane = frame.getContentPane(); contentPane.add(scrollPane, BorderLayout.CENTER);The following is an example to add JList to Scroll pane:Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame { static JFrame frame; static JList list; public static void main(String[] args) { frame = new JFrame("JList Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String sports[]= {"Tennis", "Archery", "Football", "Fencing", "Cricket", "Squash", "Hockey", "Rugby"}; list = new JList(sports); ... Read More

3K+ Views
From doing simple to complex mathematical operations(like trigonometric, logarithmic operations etc) in python we may need to use the math() module.The python math module is used to access mathematical functions. All methods of math() function are used for integer or real type objects but not for complex numbers.To use this function, we need to import it in our codeimport mathConstantsWe use these constants for calculation in python -ConstantsDescriptionsPiReturn the value of pi: 3.141592EReturn the value of natural base e. e is 0.718282tauReturns the value of tau. tau = 6.283185infReturns the infinitenanNot a number typeNumbers and Numeric RepresentationPython provides different functions ... Read More

724 Views
To store string array in JList, at first create String array list:String sports[]= { "Football", "Fencing", "Cricket", "Squash", "Hockey", "Rugby"};Now, set it to JList:JList list = new JList(sports);The following is an example to store string array in JList:Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame { static JFrame frame; static JList list; public static void main(String[] args) { frame = new JFrame("JList Demo"); SwingDemo s = new SwingDemo(); JPanel panel = new JPanel(); String sports[]= {"Football", "Fencing", "Cricket", "Squash", "Hockey", "Rugby"}; ... Read More

448 Views
To set single selection for JList, use DefaultListSelectionModel and set it to SINGLE_SELECTION:String values[]= { "One", "Two", "Three", "Four", "Five", "Six"}; JList list = new JList(values); list.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);The following is an example to set the selection mode for JList only for single selection:Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame { static JFrame frame; static JList list; public static void main(String[] args) { frame = new JFrame("JList Demo"); SwingDemo s = new SwingDemo(); JPanel panel = new JPanel(); String values[]= { ... Read More

396 Views
To select the first item in JList, use setSelectionInterval() method:String values[]= { "One", "Two", "Three", "Four", "Five", "Six"}; JList list = new JList(values); int begn = 0; int end = 0; list.setSelectionInterval(begn, end);The following is an example to select the first item in JList:Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame { static JFrame frame; static JList list; public static void main(String[] args) { frame = new JFrame("JList Demo"); SwingDemo s = new SwingDemo(); JPanel panel = new JPanel(); String values[]= ... Read More

807 Views
In this article, we will learn how to select all the items in a JList in Java. The program creates a simple graphical user interface with a list of sports. It uses the setSelectionInterval() method to select all items in the list. This ensures that from the first item to the last item in the list, everything is selected when the program runs. Problem Statement Write a Java program to select all the items in a JList. Below is the demonstration of the same − Input sports[]= {"Football", "Fencing", "Cricket", "Squash", "Hockey", "Rugby"} Output Steps to select all ... Read More

564 Views
Let’s say the following is our int array elements:10, 50, 100, 200, 250, 300, 400, 500Here, we are mapping and creating a new value by incrementing each int element with 1:Arrays.stream(new int[] {10, 50, 100, 200, 250, 300, 400, 500}).map(val -> val + 1)Now find the average:Arrays.stream(new int[] {10, 50, 100, 200, 250, 300, 400, 500}).map(val -> val + 1).average()The following is an example to Map and create new value from int array:Exampleimport java.util.Arrays; public class Demo { public static void main(String[] args) throws Exception { Arrays.stream(new int[] {10, 50, 100, 200, 250, 300, 400, 500}).map(val -> val + 1).average() .ifPresent(System.out::println); } }Output227.25

286 Views
In C++, when classes are created, we can copy it using some copy constructor or assignment operator. In this section we will see, how to prevent object copy of a class in C++. To prevent object copy, we can follow some rules. These are like below.1. Creating private copy constructor and private assignment operator.Example#include using namespace std; class MyClass { int x; public: MyClass() { //non-parameterized constructor } MyClass(int y): x(y) { } private: MyClass(const MyClass& obj) ... Read More

546 Views
Use JList getVisibleRowCount() method to display the row count in a JList:String sports[]= {"Tennis", "Archery", "Football", "Fencing", "Cricket", "Squash", "Hockey", "Rugby"}; Jlist list = new JList(sports); int rowCount = list.getVisibleRowCount(); System.out.println("Row Count = "+rowCount);The following is an example to display row count in JList:Exampleimport java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame { static JFrame frame; static JList list; public static void main(String[] args) { frame = new JFrame("JList Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String sports[]= {"Tennis", Archery", "Football", "Fencing", "Cricket", "Squash", "Hockey", "Rugby"}; list = ... Read More

1K+ Views
C++ boost libraries are widely useful library. This is used for different sections. It has large domain of applications. For example, using boost, we can use large number like 264 in C++.Here we will see some examples of boost library. We can use big integer datatype. We can use different datatypes like int128_t, int256_t, int1024_t etc. By using this we can get precision up to 1024 easily.At first we are multiplying two huge number using boost library.Example#include #include using namespace boost::multiprecision; using namespace std; int128_t large_product(long long n1, long long n2) { int128_t ans = (int128_t) n1 * ... Read More