A JTree is a component that presents a hierarchical view of data. The user has the ability to expand or collapse individual sub-trees. A TreeNode interface defines the methods that must be implemented nodes of a JTree object. The DefaulMutableTreeNode class provides a default implementation of a TreeNode interface. We can disable the leaf of JTree by overriding the getTreeCellRendererComponent() method of DefaultTreeCellRenderer class.Syntaxpublic Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)Exampleimport java.awt.*; import javax.swing.tree.*; import javax.swing.*; public class JTreeLeafNodeDisableTest extends JFrame { private TreeNode treeNode; private JTree tree; public JTreeLeafNodeDisableTest() { setTitle("JTreeLeafNodeDisable Test"); ... Read More
This example demonstrates how do I draw a smooth line following my finger in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; public class MainActivity extends AppCompatActivity implements View.OnTouchListener { ImageView imageView; Bitmap bitmap; Canvas canvas; Paint paint; float downX = ... Read More
This example demonstrates how do I in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2− Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView; public class MainActivity extends AppCompatActivity{ Button button; TextView textView; RelativeLayout relativeLayout; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); relativeLayout = ... Read More
This example demonstrates how do I control the height and width of the default alert dialog in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.WindowManager; import android.widget.Button; import android.widget.RelativeLayout; public class MainActivity extends AppCompatActivity{ Button button; RelativeLayout relativeLayout; Context ... Read More
This example demonstrates how do I pass an arrayList to another activity using intends in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to src/MainActivity.javaimport android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import java.util.ArrayList; public class MainActivity extends AppCompatActivity{ Button button; ArrayList numbers = new ArrayList(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... Read More
Already own bitcoins but want either just exchange with some conventional currency or simply get rid of them considering them mere a bubble of widening hype. However, it is not as easy as buying them. Got lines of stress on your forehead? Do not worry! Here is the complete guide for your easy comprehension of the entire process −There are two ways to sell your bitcoins −ExchangesDirect TradeExchange Although, this carries a number of disadvantages yet exchanges appear to be one of the major solutions if you want cash out of the selling of your crypto. These exchanges play the role ... Read More
An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Printing the Exception messageYou can print the exception message in Java using one of the following methods which are inherited from Throwable class.printStackTrace() − This method prints the backtrace to the standard error stream.getMessage() − This method returns the detail message string of the current throwable object.toString() − This message prints the short description of the current throwable object.Exampleimport java.util.Scanner; public class PrintingExceptionMessage { ... Read More
The HTML DOM search property associated with the anchor tag () returns the query string part of the href property value. The query string part is after the ? in a url and is usually used to pass information to the server. It is used when a get request is sent to the server and information is embedded in cleartext in the link.SyntaxFollowing is the syntax fora) Returning the search propertyanchorObject.searchb) Setting the search propertyanchorObject.search = querystringExampleLet us see an example of HTML DOM anchor search property − Example Site Click the button to change the querystring part ... Read More
An exception is an issue (run time error) occurred during the execution of a program. Here are some example scenarios −If you have an array of size 10 if a line in your code tries to access the 11th element in this array.If you are trying to divide a number with 0 which (results to infinity and JVM doesn’t understand how to valuate it).When exception occurs the program terminates abruptly at the line that caused exception, leaving the remaining part of the program unexecuted. To prevent this, you need to handle exceptions.There are two types of exceptions in java.Unchecked Exception ... Read More
Whenever you pass inappropriate arguments to a method or constructor, an IllegalArgumentException is thrown. It is a Runtime exception therefore there is no need to handle this at the time of compilation.ExampleThe valueOf() method of the java.sql.Date class accepts a String representing a date in JDBC escape format yyyy-[m]m-[d]d and converts it into a java.sql.Date object.import java.sql.Date; import java.util.Scanner; public class IllegalArgumentExample { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter your date of birth in JDBC escape format (yyyy-mm-dd) "); String dateString = sc.next(); ... Read More