问题:我有一个方法可以从解析的ArrayList创建一个列表.我设法在GUI中显示列表,没有滚动条.但是,我有问题设置它只显示ArrayList的大小.意思是,如果大小为6,则显示的列表中应该只有6行.下面是我正在使用的代码.我尝试设置visibleRowCount如下,但它不起作用.我尝试打印出结果,它显示了更改.
private void createSuggestionList(ArrayList<String> str) {
int visibleRowCount = str.size();
System.out.println("visibleRowCount " + visibleRowCount);
listForSuggestion = new JList(str.toArray());
listForSuggestion.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listForSuggestion.setSelectedIndex(0);
listForSuggestion.setVisibleRowCount(visibleRowCount);
System.out.println(listForSuggestion.getVisibleRowCount());
listScrollPane = new JScrollPane(listForSuggestion);
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
JList theList = (JList) mouseEvent.getSource();
if (mouseEvent.getClickCount() == 2) {
int index = theList.locationToIndex(mouseEvent.getPoint());
if (index >= 0) {
Object o = theList.getModel().getElementAt(index);
System.out.println("Double-clicked on: " + o.toString());
}
}
}
};
listForSuggestion.addMouseListener(mouseListener);
textPane.add(listScrollPane);
repaint();
}
Run Code Online (Sandbox Code Playgroud)
总结一下:我希望JList显示与解析的ArrayList的大小一样多的行,而不需要滚动条 …
在C++中,char const *ptr=&ch;
和
之间的区别是什么
const char *ptr=&ch;
输入:
Hi. I am John.
My name is John. Who are you ?
Run Code Online (Sandbox Code Playgroud)
输出:
Hi
I am John
My name is John
Who are you
Run Code Online (Sandbox Code Playgroud) 我们即将开始在中型ASP.Net MVC 2网站上开发.对于典型页面,我们抓取数据并将其放在网页上,即在将数据发送到UI之前没有太多的数据预处理.
我们现在决定是否使用ORM,如果是,是哪一个.我们一直在关注EF2 AKA EF4(VS 2010中的ASP.Net实体框架).
但是,我认为在这种情况下一个简单的解决方案可能只是使用数据表.原因是,一旦我们获取数据,我们不打算移动数据或处理它,所以我不确定将强类型对象作为DTO有多大价值.此外,这种方式我们完全避免映射,因此我认为简化代码并允许更快的开发.
我应该提到预算是这个项目的一个问题,以及执行的速度.我们在任何可能的地方都在努力实现简化,既可以缩小预算,又可以缩短计划,提高性能.
我们尚未完全决定这一点,但目前倾向于没有ORM.没有ORM方法我们会好吗,还是值得的ORM?
我正在尝试创建一个在托盘中运行的C#应用程序,我可以将文件放在它的图标上.有没有办法在System Tray图标上删除文件的路径?System.Windows.Forms.NotifyIcon没有任何与拖放相关的事件.
yolk -l给我的信息是我在Ubuntu 10.04上安装了114个软件包.使用后创建新的virtualenv目录
virtualenv virt_env/virt1 --no-site-packages --clear
我切换到那个,我的提示改变了,然后yolk -l又给了我相同的114个包.
那里发生了什么?
我可以从我的页面调用我的自定义Greasemonkey的function()吗?
例如,
我创建了一个包含do_this()函数的GM脚本.我希望my-web-site.com调用do_this()函数.但我不能.
我知道,我可以通过做unsafeWindow.do_this()但这样做阻止我调用GM_xmlhttpRequest().
有任何想法吗?
我目前正在开发一个C++项目,其中经常出现动态数组.我想知道,使用new-operator初始化动态数组的正确方法是什么?我的一位同事告诉我,在构造函数中使用new是一个禁忌,因为构造函数是一个不应该容易出错或者根本不应该失败的构造.现在让我们考虑以下示例:我们有两个类,一个或多或少复杂的类State和一个StateContainer类,应该自我解释.
class State {
private:
unsigned smth;
public:
State();
State( unsigned s );
};
class StateContainer {
private:
unsigned long nStates;
State *states;
public:
StateContainer();
StateContainer( unsigned long n );
virtual ~StateContainer();
};
StateContainer::StateContainer() {
nStates = SOME_DEFINE_N_STATES;
states = new State[nStates];
if ( !states ) {
// Error handling
}
}
StateContainer::StateContainer( unsigned long n ) {
nStates = n;
try {
states = new State[nStates]
} catch ( std::bad_alloc &e ) {
// Error handling
}
}
StateContainer::~StateContainer() …Run Code Online (Sandbox Code Playgroud) 在F#中,给出以下类:
type Foo() =
member this.Bar<'t> (arg0:string) = ignore()
Run Code Online (Sandbox Code Playgroud)
为什么以下编译:
let f = new Foo()
f.Bar<Int32> "string"
Run Code Online (Sandbox Code Playgroud)
虽然以下内容不会编译:
let f = new Foo()
"string" |> f.Bar<Int32> //The compiler returns the error: "Unexpected type application"
Run Code Online (Sandbox Code Playgroud) c# ×2
c++ ×2
ado.net ×1
asp.net-mvc ×1
class ×1
f# ×1
generics ×1
greasemonkey ×1
java ×1
jlist ×1
new-operator ×1
notifyicon ×1
orm ×1
pipelining ×1
pointers ×1
python ×1
swing ×1
text ×1
virtualenv ×1
yolk ×1