Examples‎ > ‎

Document Design Mode

The sample shows how to enable or disable the Design mode for a currently loaded HTML document.

While the browser is in design mode, objects enter a UI-activated state when the user presses ENTER, clicks an object that has focus, or double-clicks the object. Objects that are UI-activated have their own window in the document. You can modify the UI only when the object is in a UI-activated state.

Note: In design mode you cannot execute JavaScript commands.
import com.jniwrapper.win32.ie.Browser;
import com.jniwrapper.win32.ie.dom.HTMLDocument;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
/**
 * The sample shows how to enable or disable the design mode for a
 * currently loaded HTML document in Browser component. In design
 * mode you cannot execute JavaScript commands.
 * <p/>
 * While the browser is in design mode, objects enter a UI-activated
 * state when the user presses ENTER, clicks an object that has focus,
 * or double-clicks the object. Objects that are UI-activated have
 * their own window in the document. You can modify the UI only when
 * the object is in a UI-activated state.
 *
 * @author Vladimir Ikryanov
 */
public class DesignModeSample {
    public static void main(String[] args) {
        final Browser browser = new Browser();
        final JButton editHtmlButton = new JButton("Enable Design Mode");
        editHtmlButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                HTMLDocument document = browser.getDocument();
                boolean designMode = document.isDesignMode();
                editHtmlButton.setText(designMode ? "Enable Design Mode" :
                        "Disable Design Mode");
                document.setDesignMode(!designMode);
            }
        });
 
        JFrame frame = new JFrame("JExplorer");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container contentPane = frame.getContentPane();
        contentPane.add(browser, BorderLayout.CENTER);
        contentPane.add(editHtmlButton, BorderLayout.NORTH);
        frame.setSize(400, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
 
        browser.navigate("http://www.google.com");
    }
}