Krantik Chavan has Published 278 Articles

How to get time in milliseconds since the Unix epoch in JavaScript?

Krantik Chavan

Krantik Chavan

Updated on 24-Sep-2019 08:30:59

1K+ Views

The standard Unix epoch is an expression in seconds. The Unix epoch or Unix time is the number of seconds elapsed since January 1, 1970.The getTime() method is used to return the millisecond representation of the Date object.To get time in milliseconds, use the following:var milliseconds = (new Date).getTime();Read More

Can we get the supported image types in Java

Krantik Chavan

Krantik Chavan

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

120 Views

Yes, we can get the supported image types with ImageIO class in Java. The following is an example to get supported image types in Java:Examplepackage my; import javax.imageio.ImageIO; public class SwingDemo {    public static void main(String[] args) throws Exception {       String[] imgTypes = ImageIO.getReaderFileSuffixes();     ... Read More

How to add action listener to JButton in Java

Krantik Chavan

Krantik Chavan

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

10K+ Views

The following is an example to add action listener to Button:Examplepackage my; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo {    private JFrame frame;    private JLabel headerLabel;    private JLabel statusLabel;    private JPanel controlPanel;    public SwingDemo(){       prepareGUI();    }    public static ... Read More

How to change Button Border in Java Swing

Krantik Chavan

Krantik Chavan

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

1K+ Views

For Button border, use createLineBorder() method in Java, which allows you to set the color of the Border as well:JButton button = new JButton("Demo Button!"); Border border = BorderFactory.createLineBorder(Color.BLUE);The following is an example to change button border in Java:Exampleimport java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; ... Read More

How to set action command to JButton in Java

Krantik Chavan

Krantik Chavan

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

4K+ Views

With set action command, here we are displaying a message in the console on the click of a button.Set the button first:JButton btn = new JButton("Demo Button");Now, set Action Listener to fire when the button is clicked:ActionListener actionListener = new ActionListener() {    public void actionPerformed(ActionEvent event) {     ... Read More

I want to call JButton doClick() method to simulate a click action in Java

Krantik Chavan

Krantik Chavan

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

1K+ Views

Let us first set a JButton:JButton btn = new JButton("DemoButton");Now, attach action listener:btn.addActionListener(new ClickListener());If you have an ActionListener attached to your button it'll fire when you call the method doClick():btn.doClick();The following is an example to call JButton doClick() method to simulate a click action:Exampleimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import ... Read More

How to change JButton font dynamically in Java?

Krantik Chavan

Krantik Chavan

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

1K+ Views

The following is an example to change JButton font dynamically:Exampleimport java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo extends JFrame {    JButton button = new JButton("Change");    int fontSize = 10;    public SwingDemo() {       setSize(500, 400);       setDefaultCloseOperation(EXIT_ON_CLOSE);   ... Read More

Java Program to create JCheckBox from text in Swing

Krantik Chavan

Krantik Chavan

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

169 Views

The following is an example to create JCheckBox from text in Swing:Exampleimport java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) {       JCheckBox checkBox1 = new JCheckBox("Cricket");       JCheckBox checkBox2 = new JCheckBox("Squash");       JCheckBox ... Read More

How to disable JCheckBox if not checked in Java

Krantik Chavan

Krantik Chavan

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

771 Views

The following is an example to disable JCheckBox if not checked in Java:Exampleimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JCheckBox; import javax.swing.JOptionPane; public class SwingDemo {    public static void main(String[] args) {       JCheckBox checkBox = new JCheckBox("Demo", true);       checkBox.addActionListener(new ActionListener() {         ... Read More

How to get or set the selection state of JCheckBox in Java

Krantik Chavan

Krantik Chavan

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

351 Views

The following is an example to get or set the selection state of JCheckBox:Exampleimport java.awt.FlowLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; public class SwingDemo extends JFrame {    public SwingDemo() {       setSize(500, 500);       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       setLayout(new FlowLayout(FlowLayout.CENTER));       JCheckBox checkBox = new ... Read More

Advertisements