- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4338 Articles for Java 8
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
152 Views
Set color to MatteBorder using the Color class −Border border = new MatteBorder(5, 10, 5, 5, Color.BLUE);Now, set it to a button component in Java −JButton button = new JButton("Matte Border"); button.setBorder(border);The following is an example to set color to MatteBorder 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.border.Border; import javax.swing.border.EtchedBorder; import javax.swing.border.MatteBorder; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED); Border border = new MatteBorder(5, ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
799 Views
Let us create a MenuBar −JMenuBar menuBar = new JMenuBar();Now, set its layout to create a Vertical Menu Bar with GridLayout −menuBar.setLayout(new GridLayout(0, 1));The following is an example to create a Vertical menu bar in Java −Examplepackage my; import java.awt.GridLayout; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class SwingDemo { public static void main(final String args[]) { JFrame frame = new JFrame("MenuBar Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); menuBar.setLayout(new GridLayout(0, 1)); JMenu fileMenu = new JMenu("File"); ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
154 Views
Set an EtchedBorder from BorderFactory class −EtchedBorder etchedBorder = (EtchedBorder)BorderFactory.createEtchedBorder();Now, set it for a component −JButton button = new JButton("Etched Border"); button.setBorder(etchedBorder);The following is an example to set an EtchedBorder from BorderFactory class to a component −Examplepackage my; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED); EtchedBorder etchedBorder = (EtchedBorder)BorderFactory.createEtchedBorder(); JButton raisedButton = new JButton("Raised Border"); ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
205 Views
To create a left-right split pane, let us create two components and split them −JComponent one = new JLabel("Left Split"); one.setBorder(BorderFactory.createLineBorder(Color.MAGENTA)); JComponent two = new JLabel("Right Split"); two.setBorder(BorderFactory.createLineBorder(Color.ORANGE));Now, we will split them. The two components will be split one to the left of the other using HORIZONTAL_PANE constant −JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, one, two);The following is an example to create a left-right split pane in Java −Examplepackage my; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JSplitPane; public class SwingDemo { public static void main(String[] a) { JFrame frame = new JFrame("SplitPane ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
5K+ Views
Let us first create a table with DefaulTabelMode −DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel);Now, add a column to the table −tableModel.addColumn("Languages");The insertRow() method will now add a row −tableModel.insertRow(0, new Object[] { "CSS" }); tableModel.insertRow(0, new Object[] { "HTML5" }); tableModel.insertRow(0, new Object[] { "JavaScript" }); tableModel.insertRow(0, new Object[] { "jQuery" });The following is an example to add a new row to JTable −Examplepackage my; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo { public static void main(String[] argv) throws Exception { DefaultTableModel tableModel = new DefaultTableModel(); ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
98 Views
To set the alignment of the label content along the X axis on the left, use the setHorizontalAlignment() method and set the location. Let us first set a label component. We have set the label background color as well so that we can check the alignment of the label’s content properly −JLabel label = new JLabel("Country "); label.setPreferredSize(new Dimension(190, 100)); label.setOpaque(true); label.setBackground(Color.BLUE); label.setForeground(Color.WHITE);Now, we will align the label content along the X axis on the left by seeting location as LEFT −label.setHorizontalAlignment(JLabel.LEFT);The following is an example to set the alignment of the JLabel content along the X axis on the ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
2K+ Views
At first, set multiple number input fields −JTextField text1 = new JTextField(10); JTextField text2 = new JTextField(10); JTextField text3 = new JTextField(10); JTextField text4 = new JTextField(10); JTextField text5 = new JTextField(10); JTextField text6 = new JTextField(10); JTextField text7 = new JTextField(10); JTextField text8 = new JTextField(10); panel.add(text1); panel.add(text2); panel.add(text3); panel.add(text4); panel.add(text5); panel.add(text6); panel.add(text7); panel.add(text8);Now, let us add the values of the multiple number input fields created above −System.out.println(Integer.parseInt(text1.getText()) + Integer.parseInt(text2.getText()) + Integer.parseInt(text3.getText())+ Integer.parseInt(text4.getText())+ Integer.parseInt(text5.getText())+ Integer.parseInt(text6.getText())+ Integer.parseInt(text7.getText())+ Integer.parseInt(text8.getText()));Above, we have displayed the sum in the Console.The following is an example to sum multiple number input fields with ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
882 Views
Let us first create and array and add elements −String[] sports = { "Football", "Cricket", "Squash", "Baseball", "Fencing", "Volleyball", "Basketball" };Now, set the above array elements to the JOptionPane −String res = (String) JOptionPane.showInputDialog(null, "Which sports you play the most?", "Sports", JOptionPane.PLAIN_MESSAGE, null, sports, sports[0]);Above, we have also set the initial value i.e. sports(0).The following is an example to use JOptionPane with array elements in Java −Examplepackage my; import javax.swing.JOptionPane; public class SwingDemo { public static void main(String[] args) { String[] sports = { "Football", "Cricket", "Squash", "Baseball", "Fencing", "Volleyball", "Basketball" }; ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
924 Views
We have created a button component here, which will places in bottom-right corner −JButton button = new JButton("This is Demo Text!"); button.setBackground(Color.blue); button.setForeground(Color.white);Create panels now to arrange the above created button component in the bottom right −JPanel bottomPanel = new JPanel(new BorderLayout()); bottomPanel.add(button, BorderLayout.LINE_END); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(bottomPanel, BorderLayout.PAGE_END);The following is an example to place a component in bottom-right corner with BorderLayout −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo { public static void main(String[] args) { JButton button = new JButton("This is Demo Text!"); ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
1K+ Views
Let us first set an image with Image Icon class −ImageIcon icon = new ImageIcon(new URL("http://www.tutorialspoint.com/images/css.png"));Now, set it to a component −JLabel label = new JLabel(icon);Add the component to the panel −JPanel panel = new JPanel(new GridBagLayout()); panel.add(label);The following is an example to set an icon for JOptionPane −Examplepackage my; import java.awt.BorderLayout; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; public class SwingDemo { public static void main(String[] args) throws Exception { ImageIcon icon = new ImageIcon(new URL("http://www.tutorialspoint.com/images/css.png")); JLabel label = new JLabel(icon); JPanel ... Read More