Found 33676 Articles for Programming

How to add line border to JLabel in Java?

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

679 Views

Use the createLineBorder() method to ad line border to JLabel −Border border = BorderFactory.createLineBorder(Color.ORANGE); label.setBorder(border);Above, we have set the line border to color orange.The following is an example to add line border to JLabel −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("Demo Label!", JLabel.RIGHT);       label.setFont(new Font("Verdana", Font.PLAIN, 13));       Border border = BorderFactory.createLineBorder(Color.ORANGE);       label.setBorder(border);       frame.add(label);   ... Read More

Java Program to set alignment for text in JLabel

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

8K+ Views

JLabel Left AlignedThe following is an example to set left alignment for JLabel −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Label Demo");       JLabel label;       label = new JLabel("Left aligned!", JLabel.LEFT);       label.setFont(new Font("Verdana", Font.PLAIN, 13));       frame.add(label);       frame.setSize(500, 300);       frame.setVisible(true);    } }OutputJLabel Center AlignedThe following is an example to set center alignment for JLabel −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) ... Read More

How to create JLabel to hold multiline of text using HTML in Java?

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

1K+ Views

To hold multiline of text, set HTML under JLabel −JLabel = new JLabel("" + "Line1Line2",JLabel.LEFT);The above will create multiline text in the JLabel −Line1 Line2The following is an example to create JLabel to hold multiline of text −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Label Example");       JLabel label;       label = new JLabel("" + "Line1       Line2",JLabel.LEFT);       label.setBounds(100, 100, 100, 30);       label.setFont(new Font("Verdana", Font.PLAIN, 13));       frame.add(label);       frame.setSize(500,300);       frame.setLayout(null);       frame.setVisible(true);    } }Output

How to change text font for JLabel with HTML in Java?

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

995 Views

To change text font, you can use the setFont() method of JLabel −label.setFont(new Font("Verdana", Font.PLAIN, 12));The following is an example to change text font for JLabel with HTML −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Label Example");       JLabel label;       label = new JLabel("" + "ABC");       label.setBounds(50, 50, 100, 30);       label.setFont(new Font("Verdana", Font.PLAIN, 12));       frame.add(label);       frame.setSize(500,300);       frame.setLayout(null);       frame.setVisible(true);    } }Output

Java program to change JLabel text after creation

Samual Sam
Updated on 16-Sep-2024 23:24:47

3K+ Views

In this article, we will learn to change JLabel text after creation in Java. We'll cover two scenarios: changing the label text immediately after creation and updating it in response to a button click. Different approaches to change JLabel text after creation Below are the different approaches to change JLabel text after the creation − Using setText() Method Using a button click Update JLabel text using setText() method Following are the steps to update JLabel text immediately after creation − First we will import JFrame, JLabel, and ... Read More

How to change JLabel font in Java

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

14K+ Views

To change JLabel font, use the setFont() method −JLabel lable = label.setFont(new Font("Verdana", Font.PLAIN, 18));Examplepackage my; import java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Label Example");       JLabel label;       label = new JLabel("First Label");       label.setBounds(50, 50, 100, 30);       label.setFont(new Font("Verdana", Font.PLAIN, 18));       frame.add(label);       frame.setSize(300,300);       frame.setLayout(null);       frame.setVisible(true);    } }Output

Java Program to draw a line on a JFrame in Java

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

2K+ Views

The following is an example to draw a line on a JFrame −Examplepackage my; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Line2D; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo extends JFrame {    public SwingDemo() {       JPanel panel = new JPanel();       getContentPane().add(panel);       setSize(550, 300);    }    public void paint(Graphics gp) { super.paint(gp); Graphics2D graphics = (Graphics2D) gp;       Line2D line = new Line2D.Float(200, 150, 150, 220);       graphics.draw(line);    }    public static void main(String[] args) {       SwingDemo demo = new SwingDemo();       demo.setVisible(true);    } }Output

Interpreter base classes in Python

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

512 Views

Python's interactive mode works on the principle of REPL (Read - Evaluate - Print - Loop). The code module in Python's standard library provides classes nd convenience functions to set up REPL environment from within Python script.Following two classes are defined in code module:InteractiveInterpreter: This class deals with parsing and interpreter state (the user’s namespace)InteractiveConsole: Closely emulate the behavior of the interactive Python interpreter.Two convenience functions in the module are:interact(): Convenience function to run a read-eval-print loop.compile_command(): This function is useful for programs that want to emulate Python’s interpreter main loop (the REPL).Interactive Interpreter methodsrunsource(): Compile and run some source ... Read More

Package extension utility in Python

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

743 Views

When you want to add to the module search path for a specific package and work with resources included in a package, you need to use pkgutil module from Python library. It includes functions for changing the import rules for Python packages. It is also possible to load non-code resources from files distributed within a package.extend_path(path, name)Extend the search path for the modules which comprise a package. Intended use is to place the following code in a package’s __init__.pyimport pkgutil __path__ = pkgutil.extend_path(__path__, __name__)extend_path() scans sys.path for directories that include a subdirectory named for the package given as the second ... Read More

POP3 protocol client in Python

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

684 Views

The poolib module from Python's standard library defines POP3 and POP3_SSL classes. POP3 class encapsulates a connection to a POP3 server and implements the protocol as defined in RFC 1939. POP3_SSL classsupports POP3 servers that use SSL as an underlying protocol layer.POP3 protocolis obsolescent as its implementation quality of POP3 servers is quite poor. If your mailserver supports IMAP, it is recommended to use the imaplib.IMAP4 class.Both classes have following methods defined −getwelcome()Returns the greeting string sent by the POP3 server.user(username)Send user command, response should indicate that a password is required.pass_(password)Send password.Stat()Get mailbox status. The result contains 2 integers: (message ... Read More

Advertisements