Found 9150 Articles for Object Oriented Programming

Check whether a node is a root node or not in JTree

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

295 Views

To check whether a node is a root node or not, use the isRoot() method. This returns a boolean value. TRUE if the node is a root node, else FALSE is returned. For example, TRUE is returned since the following node is a root node −node.isRoot()Another example, FALSE is returned since the following node isn’t a root node −node2.isRoot()The following is an example to check whether a node is a root node or not −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 ... Read More

How to create a Matte-look border using a solid color in Java?

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

160 Views

The matte border gives a “matte” look. Let’s say the following is our component −JLabel label; label = new JLabel("This has matte border!");Let us create a matte border with BorderFactory class. Here, we have given color YELLOW using the Color class −label.setBorder(BorderFactory.createMatteBorder(3, 5, 10, 5, Color.YELLOW));The following is an example to create a Matte-look border −Examplepackage my; import javax.swing.BorderFactory; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("This ... Read More

How to create etched border for a component using BorderFactory class in Java?

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

311 Views

The etched border gives an ‘etched’ look. Let’s say the following is our component −JLabel label; label = new JLabel("This has etched border with an 'etched' look!");Let us create an etched border with BorderFactory class −label.setBorder(BorderFactory.createEtchedBorder());The following is an example to create etched border for a component using BorderFactory class −Examplepackage my; import javax.swing.BorderFactory; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("This has etched border with an 'etched' look!"); ... Read More

How to enable multiple selections in a JFileChooser Dialog with Java?

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

153 Views

To enable multiple selections in a JFileChooser dialog, use the setMultiSelectionEnabled() to be TRUE −JFileChooser file = new JFileChooser(); file.setMultiSelectionEnabled(true);The following is an example to enable multiple selections in a JFileChooser Dialog −Examplepackage my; import javax.swing.JFileChooser; public class SwingDemo {    public static void main(String[] args) {       JFileChooser file = new JFileChooser();       file.setMultiSelectionEnabled(true);       file.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);       file.setFileHidingEnabled(false);       if (file.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {          java.io.File f = file.getSelectedFile();          System.err.println(f.getPath());       }    } }Output

Check if hidden files are displayed in the FileChooser or not in Java

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

95 Views

The result FALSE for is FileHidingEnabled() means the hidden files are displayed in the FileChooser. The following will display FALSE since file isn’t hidden −JFileChooser file = new JFileChooser(); file.setMultiSelectionEnabled(false); file.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); file.setFileHidingEnabled(false); boolean res = file.isFileHidingEnabled();Above, at first, we have displayed the file by setting hidden to be FALSE −file.setFileHidingEnabled(false);The following is an example −Examplepackage my; import javax.swing.JFileChooser; public class SwingDemo {    public static void main(String[] args) {       JFileChooser file = new JFileChooser();       file.setMultiSelectionEnabled(false);       file.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);       file.setFileHidingEnabled(false);       boolean res = file.isFileHidingEnabled();       System.out.println("File are ... Read More

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

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

114 Views

To set the JSlider vertical, use the VERTICAL constant while creating the slider. Let us create a new Slider −JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, 60);The other parameter values set above allows you to include the minimum, maximum and the initial value of the slider.The following is an example to set the slider vertical and move bottom-to-top −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); ... Read More

How to set raised and lowered SoftBevelBorder for components in Java. Also set the border color.

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

138 Views

Let us see how to set the raised SoftBevelBorder −Border raisedBorder = new SoftBevelBorder(    SoftBevelBorder.RAISED, Color.GREEN, Color.GREEN.darker(), Color.MAGENTA, Color.magenta.brighter());Let us see how to set the lowered SoftBevelBorder −Border loweredBorder = new SoftBevelBorder(    SoftBevelBorder.LOWERED, Color.ORANGE, Color.YELLOW.darker(), Color.BLUE, Color.yellow.brighter());The following is an example to set raised and lowered SoftBevelBorder for components in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.Border; import javax.swing.border.SoftBevelBorder; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       Border raisedBorder = ... Read More

Java program to set title position

George John
Updated on 11-Sep-2024 12:25:16

1K+ Views

In this article, you'll learn how to position the title of a border in a Java Swing application using the setTitlePosition() method. We'll position the title above the border's top line by utilizing the TitledBorder.ABOVE_TOP constant. This technique is useful for customizing the appearance of your Swing components. To set title position, use the setTitlePosition() method in Java. Let’s say we have to position the title above the border's top line. For that, use the constant ABOVE_TOP for the border − setTitlePosition(TitledBorder.ABOVE_TOP); Steps to set title position Following are the steps to set title position in Java − ... Read More

How to set TitiledBorder Direction in Java?

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

155 Views

To set TitleBorder direction, you need to use the constants and set it for border. For example, for direction center −TitledBorder border = BorderFactory.createTitledBorder("Border"); border.setTitlePosition(TitledBorder.CENTER);Above, we have set the setTitlePosition() for the direction.The following is an example to set TitledBorder direction in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.TitledBorder; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       TitledBorder border = BorderFactory.createTitledBorder("Border");       border.setTitlePosition(TitledBorder.CENTER);       TitledBorder border2 = new TitledBorder(   ... Read More

How to set border color for SoftBevelBorder in Java?

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

285 Views

To set the border color for SoftBevelBorder in Java, use the Color class and set the color while creating the border −SoftBevelBorder border = new SoftBevelBorder(    BevelBorder.RAISED, Color.ORANGE, Color.ORANGE.darker(), Color.BLUE, Color.magenta.brighter());We have set the following colors above as parameters −highlightOuterColor: color to use for the bevel outer highlight highlightInnerColor : color to use for the bevel inner highlight shadowOuterColor : color to use for the bevel outer shadow shadowInnerColor : color to use for the bevel inner shadowThe following is an example to set border color for SoftBevelBorde in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import ... Read More

Advertisements