Found 4337 Articles for Java 8

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

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

61 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

84 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

90 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 in Java

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

751 Views

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);The following is an example to set title position −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.LineBorder; 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);       LineBorder lineBorder = new LineBorder(Color.orange);       TitledBorder titledBorder = BorderFactory.createTitledBorder(lineBorder, "Demo Title");   ... Read More

How to set TitiledBorder Direction in Java?

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

98 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

220 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

How to set the titled justification (position title text) of the titled border in Java

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

270 Views

To set the titled justification of the titled border, use the setTitleJustification() method. The following is an example to set the title justification of the titled border −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.LineBorder; 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);       LineBorder linedBorder = new LineBorder(Color.YELLOW);       TitledBorder titledBorder = BorderFactory.createTitledBorder(linedBorder, "Demo Title");       titledBorder.setTitleJustification(TitledBorder.LEFT);       JLabel label = new JLabel();       ... Read More

How to add a title to an existing line border in Java?

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

250 Views

Here, we will see how to add a title to an existing Line border. Let’s say we have a label and the border is to be set −LineBorder linedBorder = new LineBorder(Color.blue); TitledBorder titledBorder = BorderFactory.createTitledBorder(linedBorder, "Demo Title"); JLabel label = new JLabel(); label.setBorder(titledBorder);The following is an example to add a title to an existing line border −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.LineBorder; 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);     ... Read More

Can we create nested TitiledBorder in Java?

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

82 Views

Yes, we can create nested TitledBorder. Let us first create a component for which we will set the border −JLabel label = new JLabel();Now, we will create the 1st border −TitledBorder border = BorderFactory.createTitledBorder("Top Border"); border.setTitlePosition(TitledBorder.TOP);Following is how we will creater border 2. We have set the 1st border here −TitledBorder border2 = new TitledBorder(border, "Bottom CENTER Border", TitledBorder.CENTER, TitledBorder.BOTTOM);Now, set it for the label component −label.setBorder(border2);The following is an example to create nested TitledBorder in Java −package my; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.TitledBorder; public class SwingDemo {    public static ... Read More

Program to get JTextArea font information

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

60 Views

Let’s say the following is our JTextArea −JTextArea textArea = new JTextArea("This is demo text.");Now, get the font using the Font class getFont() method as shown below −Font font = textArea.getFont(); System.out.println("Font = "+font);The following is an example to get JTextArea font information in Java −Examplepackage my; import java.awt.Font; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo {    SwingDemo(){       JFrame frame = new JFrame();       JTextArea textArea = new JTextArea("This is demo text.");       Font font = textArea.getFont();       System.out.println("Font = "+font);       frame.add(textArea);       frame.setSize(550, 300); ... Read More

Advertisements