Found 9150 Articles for Object Oriented Programming

Customize the tooltip font, color , background and foreground color in Java

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

2K+ Views

To customize the tooltip font, color and background, use UIManager.UIManager.put("ToolTip.background", Color.ORANGE); UIManager.put("ToolTip.foreground", Color.BLACK); UIManager.put("ToolTip.font", new Font("Arial", Font.BOLD, 14));Above, we have set the font with −Tooltip.fontWe have set the foreground and background color with the following above −ToolTip.foreground ToolTip.backgroundThe following is an example to customize tooltip −Examplepackage my; import java.awt.Color; import java.awt.Font; import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.UIManager; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame.setDefaultLookAndFeelDecorated(true);       JFrame frame = new JFrame("Register!");       JLabel label1, label2, ... Read More

Make the JSlider vertical and move top-to-bottom in Java

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

265 Views

To set the JSlider to be vertical, use the VERTICAL constant while creating the slider −JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, 60);Now, for the inverted slider i.e. moving from top-to-bottom −slider.setInverted(true);The following is an example to set the slider vertical and move top-to-bottom −Examplepackage my; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Frame with Slider");       JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, 60);       slider.setInverted(true);       slider.setMinorTickSpacing(5);       slider.setMajorTickSpacing(20);     ... Read More

How to display the vertical and horizontal scrollbars always even if it is not required

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

107 Views

Use the following constants for the JScrollBar to display the vertical and horizontal scrollbars always even if it is not required −scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);The following is an example to display the vertical and horizontal scrollbars always even if it is not required −Examplepackage my; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JButton button1 = new JButton("Questions and Answers");       JButton button2 = new JButton("Videos");       JButton ... Read More

How to set horizontal gap between elements in a GridLayout with Java?

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

4K+ Views

Use the setHgap() method to set the horizontal gap between elements in a GridLayout. Let’s say we have a GridLaypout −GridLayout layout = new GridLayout(2, 4);Set the horizontal gap −layout.setHgap(25);The following is an example −Examplepackage my; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Sections");       JPanel panel = new JPanel();       panel.setBackground(Color.blue);       GridLayout layout = new GridLayout(2, 4);     ... Read More

Why the main () method in Java is always static?

raja
Updated on 30-Jul-2019 22:30:26

17K+ Views

Java main() method is always static, so that compiler can call it without the creation of an object or before the creation of an object of the class.In any Java program, the main() method is the starting point from where compiler starts program execution. So, the compiler needs to call the main() method.If the main() is allowed to be non-static, then while calling the main() method JVM has to instantiate its class.While instantiating it has to call the constructor of that class, There will be ambiguity if the constructor of that class takes an argument.Static method of a class can be ... Read More

How to freeze an Object in JavaScript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

175 Views

In the Real time world javascript doesn't have traditional classes as seen in other languages. It has objects and constructors. Object.freeze() is one among many constructor methods helps to freeze an object.Freezing an object does not allow new properties to be added to the object and also prevents the object from changing its own properties. Object.freeze() will always try to preserve the enumerability, configurability, writability and the prototype of the object. It won't create a frozen copy.Applications1) freeze() is used for freezing objects and arrays.2) freeze() is used to make an object immutable.SyntaxObject.freeze(obj)ExampleLive Demo // an object is created ... Read More

Can we define an abstract class with no abstract methods in Java?

raja
Updated on 22-Nov-2023 09:15:56

11K+ Views

Yes, we can declare an abstract class with no abstract methods in Java. An abstract class means that hiding the implementation and showing the function definition to the user. An abstract class having both abstract methods and non-abstract methods. For an abstract class, we are not able to create an object directly. But Indirectly we can create an object using the subclass object. A Java abstract class can have instance methods that implement a default behavior. An abstract class can extend only one class or one abstract class at a time. Declaring a class as abstract with no abstract methods means that we don't allow it ... Read More

Why an interface doesn\\'t have a constructor whereas an abstract class have a constructor in Java?

Shriansh Kumar
Updated on 01-Sep-2025 13:16:22

9K+ Views

Interfaces in Java are used for defining a contract that classes can implement. They can contain method signatures, default methods, static methods, and constants. we must implement the methods defined in the interface in the implementing class. Constructor in an Interface A Constructor is to initialize the non-static members of a particular class with respect to an object. An Interface in Java doesn't have a constructor because all data members in interfaces are public static final by default, they are constants (assign the values at the time of declaration). There are ... Read More

What are the differences between mean.io and mean.js in javascript?

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

139 Views

Differences between Mean.io and Mean.jsThe MEAN is a stack framework. When combined with Mongodb, node.js, express.js and angular.js it helps to create a complete javascript web app. A software developer from Israel, Amos Haviv was the first person to initiate Mean.io. Mean.js is simply a fork out from Mean.io. When developers closely observe these two variations they perceive that Mean.io has a different objective than Mean.js. The only reason might be that Mean.io is not as elegant as Mean.js. When a developer completely understands Stack, mostly he prefers Mean.js.Let's look where Mean.io and Mean.js differ1) Boilerplate generation and scaffoldingThese are ... Read More

Why an interface cannot implement another interface in Java?

raja
Updated on 22-Nov-2023 09:29:18

12K+ Views

An interface cannot implement another interface in Java. An interface in Java is essentially a special kind of class. Like classes, the interface contains methods and variables. Unlike classes, interfaces are always completely abstract. An interface is defined just like a class except for the keyword interface in place of a class, the variables are declared in an interface are static and final and the methods are defined in an interface are public abstract methods. An interface can extend any number of interfaces but one interface cannot implement another interface, because if any interface is implemented then its methods must be defined and ... Read More

Advertisements