Swing – Unable to switch JPANEL after loading the JCEF browser window

I tried to use jcef browser in my swing application but encountered a problem.
First of all, I could not add jcef browser as a JPanel component on jFrame. Then I tried Add directly on jframe
[code] getContentPane().add(browser.getUIComponent(),BorderLayout.CENTER); [/ code]

Now when the browser window is loaded into JFrame Internally, if I want to switch with other Jpanel, then it can’t work in any way
I can’t switch the screen after loading the CEF browser. Can anyone point out what I need to do. This is my test jframe.
p>

import org.cef.CefApp;
import org.cef.CefClient;
import org.cef.browser.CefBrowser;
import javax. swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt. event.WindowAdapter;
import java.awt.event.WindowEvent;

public class CardLayoutTst extends JFrame {
static CefBrowser browser = null;
static CefClient client = null ;
private static final long serialVersionUID = 1L;
private JPanel cardPanel, jp1, jp2, buttonPanel;
private JLabel jl1, jl2;
private JButton btn1, btn2;
private CardLayout cardLayout = new CardLayout( );

public CardLayoutTst() {
setTitle("Test med CardLayout");
setSize(400, 300);
cardPanel = new JPanel();
buttonPanel = new JPanel();
cardPanel.setLayout(cardLayout);
jp1 = new JPanel();
jp2 = new JPanel();
jl1 = new JLabel("Card 1");
jl2 = new JLabel("Card 2");
jp1.add(jl1);
jp2.add(jl2);
cardPanel.add(jp1, "1");
cardPanel.add(browser.getUIComponent(), "2");
btn1 = new JButton("Show Card 1");
btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
cardLayout.show(cardPanel, "1");
}
} );
btn2 = new JButton("Show Card 2");
btn2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
cardLayout.show(cardPanel, "2");
}
});
buttonPanel.add(btn 1);
buttonPanel.add(btn2);
add(cardPanel, BorderLayout.NORTH);
add(buttonPanel, BorderLayout.SOUTH);

addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
CefApp.getInstance().dispose();
dispose();
}
});

}

public static void main(String[] args) {
client = CefApp.getInstance().createClient() ;
browser = client.createBrowser("http://www.google.com", false, false);

EventQueue.invokeLater(new Runnable() {
@ Override
public void run() {
CardLayoutTst frame = new CardLayoutTst();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}

}

It’s a bit late, but I ran into the same problem. A friend of mine solved the problem.

< /p>

You must create CefSettings, set windowless_rendering_enabled to false and pass this setting object to the getInstance call:

CefSettings settings = new CefSettings();
settings.windowless_rendering_enabled = false;

client = CefApp.getInstance(settings).createClient();

I tried to use my swing I used jcef browser in the application but encountered problems.
First, I could not add jcef browser as a JPanel component on jFrame. Then I tried to add directly on jframe
[code] getContentPane().add( browser.getUIComponent(),BorderLayout.CENTER); [/ code]

Now when the browser window is loaded inside the JFrame, if I want to switch with other Jpanel, then it cannot be in any way Work
I cannot switch screens after loading the CEF browser. Can anyone point out what I need to do. This is my test jframe.

import org.cef. CefApp;
import org.cef.CefClient;
import org.cef.browser.CefBrowser;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class CardLayoutTst extends JFrame {
static CefBrowser browser = null;
stat ic CefClient client = null;
private static final long serialVersionUID = 1L;
private JPanel cardPanel, jp1, jp2, buttonPanel;
private JLabel jl1, jl2;
private JButton btn1, btn2;
private CardLayout cardLayout = new CardLayout();

public CardLayoutTst() {
setTitle("Test med CardLayout");
setSize(400, 300 );
cardPanel = new JPanel();
buttonPanel = new JPanel();
cardPanel.setLayout(cardLayout);
jp1 = new JPanel();
jp2 = new JPanel();
jl1 = new JLabel("Card 1");
jl2 = new JLabel("Card 2");
jp1.add(jl1);
jp2.add(jl2);
cardPanel.add(jp1, "1");
cardPanel.add(browser.getUIComponent(), "2");
btn1 = new JButton("Show Card 1");
btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
cardLayout.show(cardPanel, "1 ");
}
});
btn2 = ne w JButton("Show Card 2");
btn2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
cardLayout.show(cardPanel, " 2");
}
});
buttonPanel.add(btn1);
buttonPanel.add(btn2);
add(cardPanel, BorderLayout.NORTH) ;
add(buttonPanel, BorderLayout.SOUTH);

addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
CefApp.getInstance().dispose();
dispose();
}
});

}

public static void main(String[] args) {
client = CefApp.getInstance().createClient();
browser = client.createBrowser("http://www.google.com", false, false );

EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
CardLayoutTst frame = new CardLayoutTst();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}

}

< /p>

It’s a bit late, but I ran into the same problem. A friend of mine solved this problem.

You have to create CefSettings, Set windowless_rendering_enabled to false and pass this setting object to the getInstance call:

CefSettings settings = new CefSettings();
settings.windowless_rendering_enabled = false;

client = CefApp.getInstance(settings).createClient();

Leave a Comment

Your email address will not be published.