由于JTree和TreeModel不提供开箱即用的工具提示,您如何看待,为JTree提供特定于项目的工具提示的最佳方法是什么?
编辑:(之后回答我自己的问题.)
@Zarkonnen:感谢getTooltipText的想法.
我发现了覆盖DefaultTreeCellRenderer的另一种(可能还是更好的)方法并且想要分享它:
public class JTreeWithToolTips {
private static class OwnRenderer extends DefaultTreeCellRenderer {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
setToolTipText("foobar" + row);
return super.getTreeCellRendererComponent(tree, value, sel,
expanded, leaf, row, hasFocus);
}
}
public static void main(String[] args) {
JTree tree = new JTree(new Object[] { "foo", "bar", "foobar" });
tree.setCellRenderer(new OwnRenderer());
ToolTipManager.sharedInstance().registerComponent(tree);
JFrame frame = new JFrame();
frame.getContentPane().add(tree);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud) 我想创建一个从Internet下载PDF文档并将其显示给用户的应用程序.我想重新使用整个核心应用程序中使用的iPhone内置PDF查看器来查看PDF文档.
有没有办法做到这一点?
如果我使用如下自动属性在C#中定义结构:
public struct Address
{
public Address(string line1, string line2, string city, string state, string zip)
{
Line1 = line1;
Line2 = line2;
City = city;
State = state;
Zip = zip;
}
public string Line1 { get; protected set; }
public string Line2 { get; protected set; }
public string City { get; protected set; }
public string State { get; protected set; }
public string Zip { get; protected set; }
}
Run Code Online (Sandbox Code Playgroud)
当我尝试构建文件时,我收到编译错误说The 'this' object cannot be …
当我在VS 2008中编写这样的代码时:
.h
struct Patterns {
string ptCreate;
string ptDelete;
string ptDrop;
string ptUpdate;
string ptInsert;
string ptSelect;
};
class QueryValidate {
string query;
string pattern;
static Patterns pts;
public:
friend class Query;
QueryValidate(const string& qr, const string& ptn):
query(qr), pattern(ptn) {}
bool validate() {
boost::regex rg(pattern);
return boost::regex_match(query, rg);
}
virtual ~QueryValidate() {}
};
Run Code Online (Sandbox Code Playgroud)
然后我像这样初始化我的结构:
.cpp
string QueryValidate::pts::ptCreate = "something";
string QueryValidate::pts::ptDelete = "something";
//...
Run Code Online (Sandbox Code Playgroud)
编译器给出以下错误:
'Patterns':'::'左边的符号必须是'ptSelect'类型:不是'QueryValidate'的成员
我究竟做错了什么?这是Visual Studio或我的代码的问题吗?我知道除了const之外的静态成员必须在声明它们的类之外定义.
我已经看过GUID Collisons的 讨论,但是如果两个客户端都在同一时间访问同一个生成GUID的网页(可能只有微秒),那么您是否想要了解是否存在GUID冲突?
我更倾向于使用纯C api编写应用程序,例如OpenGL,而不是Cocoa Touch.所以我想知道:它可行吗?我是否能够保持与Interface Builder相同的用户体验?
我已经访问过Preferred Python单元测试框架.我不仅关注Python单元测试框架,还关注单元测试的代码覆盖.到目前为止,我只遇到过coverage.py.还有更好的选择吗?
对我来说,一个有趣的选择是通过插件(类似于IronPython Studio)将cpython,Python代码的单元测试和Python代码的代码覆盖与Visual Studio 2008 集成.可以做些什么来实现这一目标?我期待着提出建议.
我的webapp是部署到websphere服务器中的更大EAR的一部分.服务器托管同一虚拟服务器上的其他应用程序数.我的webapp在servletContextListener-> contextInitialized方法中进行了一些初始化/运行状况检查.如果初始化/运行状况检查失败,我想使webapp不可用.这样做的可行方法是什么?是否会在contextInitialized中抛出RuntimeException?EAR的其余部分是否仍然可用?谢谢.
我有一个包含许多类库的解决方案,以及一个引用这些程序集的ASP .NET网站。
当我从IDE中构建解决方案时,网站引用的所有程序集都位于bin目录中。大!
当我从命令行使用MsBuild时,所有引用的程序集都不会复制到bin目录中。为什么?
我的命令行很简单:
msbuild.exe d:\myproject\mysolution.sln
Run Code Online (Sandbox Code Playgroud) 我正考虑在未来的所有webapp中使用PDO.目前(使用我迄今为止从SO中学到的东西),我在我的网站中处理数据库连接的是一个Singleton类,如下所示:
class DB {
private static $instance = NULL;
private static $dsn = "mysql:host=localhost;dbname=mydatabase;";
private static $db_user = 'root';
private static $db_pass = '0O0ooIl1';
private function __construct()
{
}
private function __clone()
{
}
public static function getInstance() {
if (!self::$instance)
{
self::$instance = new PDO(self::$dsn, self::$db_user, self::$db_pass);
self::$instance-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
return self::$instance;
}
}
Run Code Online (Sandbox Code Playgroud)
和另一个具有内容特定功能的文件(functions.php)看起来完全像这样:
function get_recent_activities ()
{
try
{
$db = DB::getInstance();
// --prepare and execute query here, fetch the result--
return $my_list_of_recent_activities;
}
catch (PDOException …
Run Code Online (Sandbox Code Playgroud)