我有一个问题,当我尝试将一个mouselistener添加到JTextPane中的JLabel或JButton时,我得到错误"无法通过调用转换转换为Mouselistener".我更喜欢将组件放在JEditorPane中.我还听说过可以使用HyperlinkEvent.
基本上我想要一个可以在JEditorPane(preffered)/ JTextPane中右键/左键单击的组件.任何帮助,将不胜感激
现在它工作(sortof)它只是重复右键点击,我不需要绘制按钮边缘.我可以在按钮的文字下划线吗?
示例代码如下......
import java.awt.*;
import javax.swing.*;
import java.awt.Color;
import javax.swing.JTextPane;
import javax.swing.JButton;
import java.applet.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class jlabeltest extends Applet {
public void init() {
jlabeltest editorPaneExample = new jlabeltest();
editorPaneExample.setSize(550, 300);
// editorPaneExample.setText("tutorialData.com");
editorPaneExample.setVisible(true);
}
public jlabeltest() {
JTextPane editorPane = new JTextPane();
editorPane.setSelectedTextColor(Color.red);
editorPane.setText("<p color='#FF0000'>Cool!</p>");
InlineB label = new InlineB("JLabel");
label.setAlignmentY(0.85f);
label.addMouseListener(new MouseAdapter() {
public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger())
{
JOptionPane.showMessageDialog(null,"Hello!");
// do your work here
}
}
});
editorPane.insertComponent(label); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用OTL来避免MyODBC上的GPL(因为它非常好)。它可以编译,但是我得到一个
“找不到[Microsoft] [ODBC Driver Manager]数据源名称,也未指定默认驱动程序”
控制台上的错误。这段代码不是我的,您可以在线上多个地方获得它。有人可以帮忙吗?
修正:我必须指定一个DSN驱动程序名称,并且我以为它要我提供TCP信息。对不起大家...
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define OTL_ODBC // Compile OTL 4.0/ODBC
// The following #define is required with MyODBC 3.51.11 and higher
#define OTL_ODBC_SELECT_STM_EXECUTE_BEFORE_DESCRIBE
// #define OTL_ODBC_UNIX // uncomment this line if UnixODBC is used
#include "otlv4.h" // include the OTL 4.0 header file
otl_connect db; // connect object
void insert()
// insert rows into table
{
otl_stream o(1, // buffer size should be == 1 always …Run Code Online (Sandbox Code Playgroud) 我试图在我的程序中检测JTextPane中超链接的右键单击.这个问题在网上确实没什么.有人能帮我吗?
public class rchltest extends Applet {
public void init() {
JPanel panel = new JPanel(false);
JEditorPane gentextp = new JTextPane();
JScrollPane scrollPane = new JScrollPane(gentextp);
panel.add(scrollPane);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
gentextp.setContentType("text/html");
gentextp.setEditable(false);
gentextp.addHyperlinkListener(new texthll());
gentextp.setPreferredSize( new Dimension( 500, 400 ) );
gentextp.setText("Here is a <a href='http://A'>hyperlink</a>");
this.add( panel );
}
}
class texthll implements HyperlinkListener {
public void hyperlinkUpdate(HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
JEditorPane pane = (JEditorPane)event.getSource();
URL url = event.getURL();
// Show the new page in the editor …Run Code Online (Sandbox Code Playgroud)