我试图为我的Java应用程序构建一个GUI.我动态添加JPanels,这是我GUI中的"行".在面板列表下面有一个添加新面板的按钮.随着List的增长,它到达父Container的末尾.然后我想使用滚动条,以便用户能够到达列表中的每个面板.
到目前为止,我尝试了JScrollPanes和Layouts,但我不知道如何让它工作.
你能给我一些建议吗?
this.setLayout(new BorderLayout());
JPanel listContainer = new JPanel();
listContainer.setLayout(BoxLayout(listContainer, BoxLayout.Y_AXIS);
this.add(new JScrollPane(listContainer), BorderLayout.CENTER);
this.add(new JButton(), BorderLayout.PAGE_END);
//then i add panels to the listContainer. this wont work, when the space is complettly used there is no scrollbar.
Run Code Online (Sandbox Code Playgroud) #include <sstream>
#include <iostream>
int main() {
double val;
std::stringstream ss("6.93758e-310");
ss >> val;
std::cout << "fail: " << ss.fail() << std::endl
}
Run Code Online (Sandbox Code Playgroud)
......我得到不同的行为:
ss.fail()
未设置,而可能需要注意的是,在这两种情况下,errno
都设置为ERANGE
.
另外,在本地我得到了与clang和gcc相同的行为,除非我明确地使用libc ++和clang(-stdlib=libc++
)而不是glibc.
我不确定正确的行为是什么,但我觉得它应该是一致的.
我目前正在尝试用C++编写OpenGL程序.当我尝试编译我的程序时,我得到了未定义的引用,我在任何地方调用我的类的成员函数,尽管我从成员函数中调用这些函数...
这些是我得到的错误消息:
make clean && make
rm -f *.o *~ main
g++ -c main.cpp -o main.o
g++ -c renderer.cpp -o renderer.o
g++ -o main main.o renderer.o -lglut -lGL -lGLEW
renderer.o: In function `Renderer::resize(int, int)':
renderer.cpp:(.text+0x299): undefined reference to `Renderer::Perspective(float*, float, float, float, float)'
renderer.o: In function `Renderer::setupShaders()':
renderer.cpp:(.text+0x43d): undefined reference to `Renderer::loadShaderSrc(char const*, int&)'
renderer.cpp:(.text+0x456): undefined reference to `Renderer::loadShaderSrc(char const*, int&)'
renderer.cpp:(.text+0x4e7): undefined reference to `Renderer::printShaderInfoLog(int)'
renderer.cpp:(.text+0x4fe): undefined reference to `Renderer::printShaderInfoLog(int)'
renderer.cpp:(.text+0x568): undefined reference to `Renderer::printProgramInfoLog(int)'
collect2: Fehler: ld gab …
Run Code Online (Sandbox Code Playgroud) 我试图获取我想要使用的接口的mac地址.
我使用此代码这样做,但我总是收到错误消息"不适当的设备ioctl"
我已经尝试使用不同的套接字,即AF_INET与SOCK_DGRAM(虽然我需要原始套接字供以后使用)没有任何区别.
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/if_ether.h>
#include <net/if.h>
int main()
{
char if_name[] = "eth0";
char mac[ETH_ALEN];
struct ifreq ifr;
int sock;
if(sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP)) < 0)
{
perror("SOCKET");
return 1;
}
// get mac address of our interface
memset(&ifr, 0, sizeof(struct ifreq));
memcpy(ifr.ifr_name, if_name, 4);
if(ioctl(sock, SIOCGIFHWADDR, &ifr) == -1)
{
perror("SIOCGIFHWADDR");
return 1;
}
memcpy(mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
printf("%x.%x.%x.%x.%x.%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
Run Code Online (Sandbox Code Playgroud)