Showing posts with label swing. Show all posts
Showing posts with label swing. Show all posts

Monday, January 15, 2018

JTable define an editor for LocalTime type

Leave a Comment

I am using Java 8, after following documentation:

I'd like to setup a specialized formatter when editing a column in my JTable. This column contains java.time.LocalTime instances.

JTable table; ... table.setDefaultEditor(LocalTime.class, new LocalTimeEditor()); 

Where LocalTimeEditor is defined by (tentatively):

public class LocalTimeEditor extends DefaultCellEditor {     JFormattedTextField ftf;    public LocalTimeEditor() {     super(new JFormattedTextField());     ftf = (JFormattedTextField) getComponent();      // Set up the editor for the LocalTime cells.     DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");     ftf.setFormatterFactory(new DefaultFormatterFactory(dateFormatter)); 

But this leads to the following compilation error:

The constructor DefaultFormatterFactory(DateTimeFormatter) is undefined 

I'd like to stay away from a solution involving SimpleDateFormat (+DateFormatter) as explained here or here, since java.util.Date should be considered legacy (see old code here).

Is there a solution to integrate DateTimeFormatter with JFormattedTextField, or am I blocked by:

I'd also like to stay away from MaskFormatter, since it does not allow easy error handling for something like: "25:70:90".

1 Answers

Answers 1

As per the argument of DefaultFormatterFactor, I created a new JFormattedTextField.AbstractFormatter

class JTFormater extends JFormattedTextField.AbstractFormatter{     final DateTimeFormatter formatter;     public JTFormater(DateTimeFormatter formatter){         this.formatter =  formatter;     }     @Override     public Object stringToValue(String text) throws ParseException {         return formatter.parse(text);     }      @Override     public String valueToString(Object value) throws ParseException {         if(value instanceof TemporalAccessor){             return formatter.format((TemporalAccessor) value);         } else{             throw new ParseException("not a valid type at", 0);         }     } } 

From this I could parse and display LocalTime's, although in my implementation it is pretty clumsy.

Read More

Thursday, December 21, 2017

Java JScrollpane not visible

Leave a Comment

I'm trying to display a series of buttons in a JScrollpane. Reading around, I managed to exit with this code, but nothing is displayed. I do not understand a possible mistake. Thank you for help

As suggested I made some changes, I edited but not works

EDITED or I'm stupid, or here is some other problem. Here is my complete code with the output image

public class Main extends javax.swing.JFrame {     private final JPanel gridPanel;      public Main() {         initComponents();         // EXISTING PANEL         gridPanel = new JPanel();         JScrollPane scrollPane = new JScrollPane(gridPanel);         scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);         JPanel borderLayoutPanel = new JPanel(new BorderLayout());         borderLayoutPanel.add(scrollPane, BorderLayout.CENTER);          this.Avvio();     }      private void Avvio() {         JPanel pane = new JPanel(new GridBagLayout());         pane.setBorder(BorderFactory.createLineBorder(Color.BLUE));         pane.setLayout(new GridBagLayout());          for (int i = 0; i < 10; i++) {             JButton button;             GridBagConstraints c = new GridBagConstraints();             c.fill = GridBagConstraints.HORIZONTAL;             c.anchor = GridBagConstraints.PAGE_START;              button = new JButton("Button 1");             c.weightx = 0.5;             c.gridx = 0;             c.gridy = i;             pane.add(button, c);              button = new JButton("Button 2");             c.gridx = 1;             c.gridy = i;             pane.add(button, c);              button = new JButton("Button 3");             c.gridx = 2;             c.gridy = i;             pane.add(button, c);          }         gridPanel.add(pane);         gridPanel.revalidate();         gridPanel.repaint();      } } 

enter image description here

4 Answers

Answers 1

Problems noted:

  • Avvio - the pane layout was reset during each loop. Set it once before the loop.
  • Avvio - the pane was added to the grid pane in each loop. Add it once after the loop.
  • Avvio - the constraints place the buttons in the same grid locations. With the previous two issues fixed, only the last three buttons placed appear.

I'm assuming you want three buttons in a row, so I changed the loop to use the counter as a row counter. The code below will create ten rows of three buttons.

What appears: enter image description here

import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout;  import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.WindowConstants;   public class Main extends javax.swing.JFrame {     private JPanel gridPanel;      public Main() {          this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);         this.setSize(600,400);          //EXISTING PANEL         gridPanel = new JPanel();         JScrollPane scrollPane = new JScrollPane(gridPanel);         scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);         JPanel borderLayoutPanel = new JPanel(new BorderLayout());         borderLayoutPanel.add(scrollPane, BorderLayout.CENTER);          this.Avvio();         this.add(borderLayoutPanel, BorderLayout.CENTER);         this.setVisible(true);     }      private void Avvio() {         JPanel pane = new JPanel(new GridBagLayout());         pane.setBorder(BorderFactory.createLineBorder(Color.BLUE));         pane.setLayout(new GridBagLayout());             for (int i = 0; i < 10; i++) {                JButton button;                GridBagConstraints c = new GridBagConstraints();                c.fill = GridBagConstraints.HORIZONTAL;                c.anchor = GridBagConstraints.PAGE_START;                 button = new JButton("Button 1");                c.weightx = 0.5;                c.gridx = 0;                c.gridy = i;                pane.add(button, c);                 button = new JButton("Button 2");                c.gridx = 1;                c.gridy = i;                pane.add(button, c);                 button = new JButton("Button 3");                c.gridx = 2;                c.gridy = i;                pane.add(button, c);             }            gridPanel.add(pane);            gridPanel.revalidate();            gridPanel.repaint();      }      public static void main(String args[]) {        new Main();     }       } 

Answers 2

Alright, from your comments in another answer:

No problem for compile , simply the Jpanel is empty. The buttons does not appear.

After calling this.Avvio(); you must call:

this.add(scrollPane); this.pack(); 

This will produce the following outputs (before and after resizing it):

enter image description hereenter image description here

But there's still no JScrollPanel

This at least solves the first problem, however you have more errors in your code, some of which have already been commented in other answers:

  1. You're extending JFrame, this isn't needed as you can create a JFrame instance / object and use it later. You're never changing the JFrame's behavior and that's why it's not needed to extend it. See Extends JFrame vs. creating it inside the program for more information about this.

  2. You're not calling pack() nor setSize(...) this creates a tiny window, which you need to manually resize. Call pack() recommended before making your JFrame visible. (As suggested at the beginning of this answer).

  3. You're calling .invokeLater() method twice. You need to call it just once, I prefer this way:

    SwingUtilities.invokeLater(() -> new Main()); //Note there is no call to .setVisible(true); as per point #1. It should go later in the program like:  frame.setVisible(true); 
  4. You're calling gridPanel.revalidate(); and gridPanel.repaint() while it doesn't affect your program, it's not needed as your GUI is still not visible, and thus those calls have no effect on your program, you can safely remove them.

  5. You're creating a new GridBagConstraints object on each iteration of the for loop, you can just change its properties inside it and declaring it outside the for loop, which will make your program better.

After following the above recommendations, you can end up with a code like this one:

import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout;  import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities;  public class Main {     private final JPanel gridPanel;     private JFrame frame;      public Main() {         // EXISTING PANEL         gridPanel = new JPanel();         JScrollPane scrollPane = new JScrollPane(gridPanel);         scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);         JPanel borderLayoutPanel = new JPanel(new BorderLayout());         borderLayoutPanel.add(scrollPane, BorderLayout.CENTER);          this.Avvio();          frame.add(scrollPane);         frame.pack();         frame.setVisible(true);     }      private void Avvio() {         JPanel pane = new JPanel(new GridBagLayout());         pane.setBorder(BorderFactory.createLineBorder(Color.BLUE));         pane.setLayout(new GridBagLayout());          for (int i = 0; i < 10; i++) {             JButton button;             GridBagConstraints c = new GridBagConstraints();             c.fill = GridBagConstraints.HORIZONTAL;             c.anchor = GridBagConstraints.PAGE_START;              button = new JButton("Button 1");             c.weightx = 0.5;             c.gridx = 0;             c.gridy = i;             pane.add(button, c);              button = new JButton("Button 2");             c.gridx = 1;             c.gridy = i;             pane.add(button, c);              button = new JButton("Button 3");             c.gridx = 2;             c.gridy = i;             pane.add(button, c);          }         gridPanel.add(pane);     }      public static void main(String args[]) {         /* Create and display the form */         SwingUtilities.invokeLater(() -> {             new Main();         });     } } 

Which still produces this output:

enter image description here

BUT... We still can improve it a little more!

We may have two nested for loops, for the GridBagConstraints properties as well as the generation of the buttons:

import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout;  import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities;  public class ScrollablePaneWithButtons {     private static final int ROWS = 10;     private static final int COLS = 3;      private JFrame frame;     private JPanel pane;     private JButton[][] buttons;     private GridBagConstraints gbc;     private JScrollPane scroll;     private JButton[] menuButtons;     private JPanel menuPane;      public static void main(String[] args) {         SwingUtilities.invokeLater(new ScrollablePaneWithButtons()::createAndShowGui);     }      private void createAndShowGui() {         frame = new JFrame(this.getClass().getSimpleName());          pane = new JPanel();         pane.setLayout(new GridBagLayout());          menuPane = new JPanel();         menuPane.setLayout(new GridLayout(1, 3));          buttons = new JButton[ROWS][COLS];          menuButtons = new JButton[] {new JButton("Edit"), new JButton("Delete"), new JButton("Sort Fields")};          gbc = new GridBagConstraints();          gbc.fill = GridBagConstraints.HORIZONTAL;         gbc.anchor = GridBagConstraints.PAGE_START;         gbc.weightx = 0.5;          for (int i = 0; i < ROWS; i++) {             for (int j = 0; j < COLS; j++) {                 buttons[i][j] = new JButton("Button " + (j + 1));                  gbc.gridx = j;                 gbc.gridy = i;                  pane.add(buttons[i][j], gbc);             }         }          scroll = new JScrollPane(pane, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);          for (JButton b : menuButtons) {             menuPane.add(b);         }         frame.add(scroll);         frame.add(menuPane, BorderLayout.SOUTH);          frame.pack();         frame.setVisible(true);         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     } } 

And this example is (in my opinion) easier to read and follow up. And this is the output the above code is generating:

enter image description here

You can still choose which code to use, either doing the modifications at the first part of this answer, the second one following the recommendations above or the last one which is shorter.

Answers 3

There are several things to do to make it work:

  1. Add a main method
  2. This main method is the entry point. This makes sure the swing-code runs in the AWT-thread. This is what the SwingUtilities.invokeLater is for
  3. Instantiate, pack and display the frame. The size setting is only for experimenting with the scrollpane
  4. Declare the gridPanel as an instance variable
  5. wrap the gridPanel with the scrollPane
  6. Optionally, wrap the scrollPane with the borderLayoutPanel
  7. Invoke the Avvio method because this is the one that adds the buttons
  8. Add the outmost element to the frame

Here is the fixed code:

public class MyFrame extends javax.swing.JFrame {      public static void main(String[] args) {         SwingUtilities.invokeLater(() -> {             MyFrame frame = new MyFrame();             frame.pack();             frame.setSize(600, 300);             frame.setVisible(true);         });     }      private JPanel gridPanel;      public MyFrame() {         this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);          gridPanel = new JPanel(new GridLayout(0, 1));         JScrollPane scrollPane = new JScrollPane(gridPanel);         scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);         JPanel borderLayoutPanel = new JPanel(new BorderLayout());         borderLayoutPanel.add(scrollPane, BorderLayout.CENTER);         this.Avvio();         this.add(borderLayoutPanel, BorderLayout.CENTER);     }       private void Avvio() {...} } 

Answers 4

I have simplified the program and removed all the mistakes and bad practices. (Missing package, unnecessary panels, calling invokeLater() twice and others.)

Here is a working example:

package com.zetcode;  import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane;  public class JavaScrollPaneEx extends JFrame {      public JavaScrollPaneEx() {          initUI();     }      private void initUI() {          JPanel panel = new JPanel(new BorderLayout());          JPanel buttonPanel = createButtonPanel();         JScrollPane scrollPane = new JScrollPane(buttonPanel);          panel.add(scrollPane, BorderLayout.CENTER);         add(panel);          setTitle("Buttons in JScrollBar");         setSize(350, 250);         setLocationRelativeTo(null);         setDefaultCloseOperation(EXIT_ON_CLOSE);      }      private JPanel createButtonPanel() {          JPanel panel = new JPanel(new GridBagLayout());          GridBagConstraints c = new GridBagConstraints();         c.fill = GridBagConstraints.HORIZONTAL;         c.anchor = GridBagConstraints.PAGE_START;         c.insets = new Insets(5, 5, 5, 5);          for (int i = 0, j = 0; i < 5; i++) {              JButton btn = new JButton("Button " + (j + 1));             c.weightx = 0.5;             c.gridx = i;             c.gridy = 0;             panel.add(btn, c);              btn = new JButton("Button " + (j + 2));             c.gridx = i;             c.gridy = 1;             panel.add(btn, c);              btn = new JButton("Button " + (j + 3));             c.gridx = i;             c.gridy = 2;             panel.add(btn, c);              j += 3;         }          return panel;     }      public static void main(String args[]) {          EventQueue.invokeLater(() -> {             JavaScrollPaneEx ex = new JavaScrollPaneEx();             ex.setVisible(true);         });     } } 

And this is the screenshot.

enter image description here

And since I consider GridBagLayout to be a very bad layout manager, I have created a similar example with MigLayout manager.

We need the following Maven dependency for this example:

<dependency>     <groupId>com.miglayout</groupId>     <artifactId>miglayout-swing</artifactId>     <version>5.0</version> </dependency> 

The source:

package com.zetcode;  import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JButton; import javax.swing.JFrame; import static javax.swing.JFrame.EXIT_ON_CLOSE; import javax.swing.JPanel; import javax.swing.JScrollPane; import net.miginfocom.swing.MigLayout;  public class JavaScrollPaneEx2 extends JFrame {      public JavaScrollPaneEx2() {          initUI();     }      private void initUI() {          JPanel panel = new JPanel(new BorderLayout());          JPanel buttonPanel = createButtonPanel();         JScrollPane scrollPane = new JScrollPane(buttonPanel);          panel.add(scrollPane, BorderLayout.CENTER);         add(panel);          setTitle("Buttons in JScrollBar");         setSize(350, 250);         setLocationRelativeTo(null);         setDefaultCloseOperation(EXIT_ON_CLOSE);      }      private JPanel createButtonPanel() {          JPanel panel = new JPanel(new MigLayout());          for (int i = 0, j = 0; i < 5; i++) {              JButton btn1 = new JButton("Button " + (j + 1));             JButton btn2 = new JButton("Button " + (j + 2));             JButton btn3 = new JButton("Button " + (j + 3));             JButton btn4 = new JButton("Button " + (j + 4));             JButton btn5 = new JButton("Button " + (j + 5));              panel.add(btn1, "sgx");             panel.add(btn2, "sgx");             panel.add(btn3, "sgx");             panel.add(btn4, "sgx");             panel.add(btn5, "sgx, wrap");              j += 5;         }          return panel;     }      public static void main(String args[]) {          EventQueue.invokeLater(() -> {             JavaScrollPaneEx2 ex = new JavaScrollPaneEx2();             ex.setVisible(true);         });     } } 
Read More

Monday, June 26, 2017

Can multiple showMessageDialogs break swing?

Leave a Comment

This is simplified code, which would be called from pressing a button in my main JFrame class. Using this code, and then dismissing one of the resulting dialogs, causes all of my active windows in my Java session to either lock up or just go away.

//Broken code private void buttonActionPerformed(java.awt.event.ActionEvent evt) {     List<JFrame> frameList = new ArrayList<>();     frameList.add(new TestJFrame());     frameList.add(new TestJFrame());      frameList.forEach(frame -> frame.setVisible(true));      frameList.forEach(frame -> {         SwingUtilities.invokeLater(() -> {             JOptionPane.showMessageDialog(frame, "Msg", "Title", 0);             frame.setVisible(false);             frame.dispose();         });     }); } 

However, if I were to remove the SwingUtilities.invokeLater() section then it works like I would expect (dialog pops up, close the dialog, window goes away, repeat).

//Working code private void buttonActionPerformed(java.awt.event.ActionEvent evt) {     List<JFrame> frameList = new ArrayList<>();     frameList.add(new TestJFrame());     frameList.add(new TestJFrame());      frameList.forEach(frame -> frame.setVisible(true));      frameList.forEach(frame -> {         //SwingUtilities.invokeLater(() -> {             JOptionPane.showMessageDialog(frame, "Msg", "Title", 0);             frame.setVisible(false);             frame.dispose();         //});     }); } 

I'd rather not use the second one because the actual code is being started in a background thread that is notifying a set of listeners, so if I were to use the second one then it would block up the thread and slow down listeners until the user responds (when I could be processing during that time). What about the invokeLater() is breaking me? Is this expected behavior?

NOTE: This is simplified code pulled out of how I'm actually using it, but the core issue still exists (I have multiple JFrames, and if multiple JOptionPane.showMessageDialog()s were put on invokeLater()s for different JFrames then it breaks me. I tested the above code with a new, isolated, JFrame class created in Netbeans and was able to reproduce the error.

EDIT: I can't seem to reproduce the error in Windows, only seems to happen in Linux.

3 Answers

Answers 1

It is most likely invokeLater() which is breaking your code. If you want to thread this action try using a simple thread or

  EventQueue.invokeLater(new Runnable()    {             public void run()              { //Your joptionpane here              }      });` 

Answers 2

Instead of invoke later i prefer using a 1) simple thread 2) TimerTask 3) ScheduledExecutorService

Use one of these methods. This is an example for using timer task

import java.util.Timer; import java.util.TimerTask; public class Task2 {    public static void main(String[] args) {      TimerTask task = new TimerTask() {       @Override       public void run() {         // task to run goes here         System.out.println("Hello !!!");       }     };     Timer timer = new Timer();     long delay = 0;     long intevalPeriod = 1 * 1000;      // schedules the task to be run in an interval      timer.scheduleAtFixedRate(task, delay,                             intevalPeriod);   } // end of main } 

If you are not satisfied you can use invoke later. But remember never use invoke and wait its a bad idea

Answers 3

Here is my approach, as I understand the problem is on the locked windows, which are waiting for an event to finish, in swing the events are related with the AWT-EventQueue.

Here is a little explanation about: https://stackoverflow.com/a/22534931/1670134

So, in order to get your window working I used the Future type:

From the java doc:

A Future represents the result of an asynchronous computation. Methods are provided to check if the computation is complete, to wait for its completion, and to retrieve the result of the computation. The result can only be retrieved using method get when the computation has completed, blocking if necessary until it is ready.

package com.stackoverflow.future;  import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit;  import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.SwingWorker;  import com.stackoverflow.frame.MyFrame;  public class MySwingWorker extends SwingWorker<Void, Void>{      @Override     protected Void doInBackground() throws Exception {         final ExecutorService service = Executors.newFixedThreadPool(1);         List<Future<JFrame>> frameList = new ArrayList<Future<JFrame>>();         frameList.add(service.submit(new SwingLoader(new MyFrame())));         frameList.add(service.submit(new SwingLoader(new MyFrame())));          try {             service.shutdown();             service.awaitTermination(5, TimeUnit.SECONDS);         } catch (InterruptedException ex) {             ex.printStackTrace();         } finally {             service.shutdownNow();         }         return null;     }      public static void main(String[] args) {         MySwingWorker mySwingWorker = new MySwingWorker();         SwingUtilities.invokeLater(mySwingWorker);     }  } 

The loader:

package com.stackoverflow.future;  import java.util.concurrent.Callable;  import javax.swing.JFrame;  public class SwingLoader implements Callable<JFrame>{      private JFrame frame;      public SwingLoader(JFrame frame){         this.frame = frame;     }      @Override     public JFrame call() throws Exception {         frame.setVisible(true);         return frame;     }  } 

NOTE: This code is just a proto, in order to provide you with ideas and it must be modified and cleaned in order to achieve the desired results.

Here you are a link with a couple of explanations of each type: http://winterbe.com/posts/2015/04/07/java8-concurrency-tutorial-thread-executor-examples/

Read More

Wednesday, April 6, 2016

Browser using JEditorPane forcing blue background

Leave a Comment

This is the code I'm using to display google in a JEditorPane

String url="http://google.com";     editorPane.setEditable(false);     try {         editorPane.setPage(url);     } catch (IOException e) {} 

But for some reason the background will always be a blue colour, doesn't matter if I call

setBackgroundColor(Color.WHITE); 

4 Answers

Answers 1

As @AndrewThompson noted in the comments JEditorPane is really behind, it supports only a subset of HTML 3.2 and CSS1, and isn't really cable of rendering any modern web pages.

I strongly suggest using an alternative, like:

  • JavaFX WebView

    Code Snippet: (no dependencies, you can run it as-is)

    import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView;  import javax.swing.*; import java.awt.*;  public class JavaFxBrowser implements Runnable {     private WebEngine webEngine;      public static void main(String[] args) {         SwingUtilities.invokeLater(new JavaFxBrowser());     }      public void loadURL(final String url) {         Platform.runLater(() -> {             webEngine.load(url);         });     }      @Override     public void run() {         // setup UI         JFrame frame = new JFrame();         frame.setVisible(true);         frame.setPreferredSize(new Dimension(1024, 600));         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);          JFXPanel jfxPanel = new JFXPanel();         frame.getContentPane().add(jfxPanel);         frame.pack();          Platform.runLater(() -> {             WebView view = new WebView();             webEngine = view.getEngine();              jfxPanel.setScene(new Scene(view));         });          loadURL("http://www.google.com");     } } 
  • Flying Saucer

    Code Sample:

    XHTMLPanel panel = new XHTMLPanel(); panel.setDocument("http://www.google.com"); 

    @see BrowsePanel.java

  • or NativeSwing

    Code Snippet:

    final JWebBrowser webBrowser = new JWebBrowser(); webBrowser.navigate("http://www.google.com"); 

    @see SimpleWebBrowserExample.java

Answers 2

A possible reason is that HTMLDocument parses three-digit color codes differently from normal. Hence, everything is shown as blue because only the blue byte (and the lowest 4 bits of the green byte) is set.

For example: #FFF would be interpreted as #000FFF, which is sharp blue.

At least this solved my problem mentioned in the comments. A possible reason for related threads on the background, too.

Answers 3

It seems you have extended JFrame in your class. So please use editorPane Object for setting the color as below

String url="http://google.com";     editorPane.setEditable(false); editorPane.setBackground(Color.WHITE);     try {         editorPane.setPage(url);     } ca 

Answers 4

I once tried using JEditorPane circa JDK1.3 and the support was awfully limited. From what i understand there has not been much advancements in that API to provide support for browsing.

I recommend you checkout DJ here. Simple to setup and use reliably.

Read More