Programming Articles - Page 2599 of 3366

How to create a List Spinner in Java?

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

351 Views

For a List Spinner, use the SpinnerListModel class. At first, let us set a list −SpinnerListModel list = new SpinnerListModel(new String[] { "Football", "Cricket", "Hockey", "Squash", "Fencing" });Now, set it and create a new JSpinner −JSpinner spinner = new JSpinner(list);The following is an example to create a List Spinner −Examplepackage my; import java.awt.GridBagLayout; import javax.swing.*; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Spinner Demo");       JPanel panel = new JPanel();       JLabel label = new JLabel("Favourite Sports − ");       panel.setLayout(new GridBagLayout());   ... Read More

Java Program to get the previous leaf from a JTree

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

167 Views

Use the getPreviousLeaf() method to get the previous leaf in a JTree. Here, we are displaying the leaf before this node “eight” on Console -System.out.println("Get Previous Leaf = "+eight.getPreviousLeaf());The following is an example to get the previous leaf from a JTree -Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing (Product1 - P66778)");       DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("Accessories (Product2 - P66779)"); ... Read More

I want to return the next node after this node in a JTree with Java

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

228 Views

Use the getNextNode() method to get the next node after this node in Java. Here, we are displaying the next node of child node “eight” -System.out.println("Next node after this node = "+eight.getNextNode());The following is an example to return the next node after this node in a JTree -Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing (Product1 - P66778)");       DefaultMutableTreeNode node2 ... Read More

How to get the leaf after this node in a JTree component with Java?

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

186 Views

Use the getNextLeaf() method to get the leaf after this node in a JTree. Here, we are displaying the leaf after node “three” in Console −System.out.println("Next leaf after this node = "+three.getNextLeaf());The following is an example to get the leaf node after this node in a JTree component −package my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing (Product1 - P66778)");       DefaultMutableTreeNode ... Read More

How to clone an object in JavaScript?

Nikhilesh Aleti
Updated on 18-Nov-2022 07:19:09

5K+ Views

An object is said to be an entity which has properties and types in it. Example, consider a Person as an object and it has properties like height, weight, age and salary. In the similar way JavaScript also have objects and their defined properties. An object in JavaScript is a complicated data type where it can store various data types in it. Let’s consider this example below const employee = { name : ‘Dhoni’, age : 41, height : 5.8, } Cloning an object using JavaScript In general, “Cloning” is ... Read More

Explain in detail about Mark and Sweep algorithm in JavaScript?

vineeth.mariserla
Updated on 04-Jul-2020 15:01:53

1K+ Views

Mark and Sweep algorithmMark and Sweep algorithm looks out for objects 'which are unreachable' rather than objects 'which are no longer needed'. This algorithm is the improvement of Reference-counting algorithm.This algorithm actually goes through 3 important steps. Root: In general, a root is a global variable that is used in the code. A window object in javascript can act as a   root. This algorithm uses global object root to find whether the objects are reachable or unreachable.This algorithm then monitors every root and also their children. While monitoring, some objects which are reachable are marked and remaining objects which are ... Read More

How to use the SimpleDateFormat class to convert a Java Date to a formatted String?

raja
Updated on 21-Nov-2023 16:11:34

162 Views

The Java SimpleDateFormat class provides convert between a Java String to a Date or Date to String. Example import java.util.Date; import java.text.SimpleDateFormat; import java.util.Calendar; public class SimpleDateFormatTest { public static void main(String[] args) { // get today's date Date today = Calendar.getInstance().getTime(); // create a date "formatter" SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss"); // create a new String using the date format String formattedDate = formatter.format(today); // prints converted date to string format System.out.println(" Date is:" + formattedDate); } } Output Date is:2023-11-21-10.39.16

What are the differences between an application and an applet in Java?

raja
Updated on 06-Feb-2020 10:13:32

2K+ Views

A Java program can be classified into two types, one is an Application and another is an Applet.ApplicationAn application is a stand-alone java program that runs with the support of a virtual machine in a client or server-side.A java application is designed to perform a specific function to run on any Java-compatible virtual machine regardless of the computer architecture.An application is either executed for the user or for some other application program.Examples of java applications include database programs, development tools, word processors, text and image editing programs, spreadsheets, web browsers, etc.Examplepublic class Demo {    public static void main(String args[]) ... Read More

How to resolve a NullPointerException in Java?

Shriansh Kumar
Updated on 20-May-2025 17:25:10

2K+ Views

The NullPointerException is a subclass of the RuntimeException class. It is defined in java.lang package of Java. In this article, we are going to understand the reasons for NullPointerException and how to resolve them. Reason for NullPointerException in Java A NullPointerException is a runtime exception thrown by the JVM when our application code, another referenced API, or the middleware encounters the following conditions: Attempting to invoke an instance method of a null object. ... Read More

Java Program to wrap text in a JTextPane and show Scrollbar

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

2K+ Views

Let’s say we have lots of content in our JTextPane component −textPane.setText("This is demo text1. This is demo text2. This is demo text3."    + "This is demo text4.This is demo text5. This is demo text6. "    + "This is demo text7. This is demo text8. This is demo text9. "    + "This is demo text10. This is demo text11. This is demo text12."    + "This is demo text13. This is demo text13. This is demo text14."    + "This is demo text15. This is demo text13. This is demo text16."    + " This is demo ... Read More

Advertisements