Wikipedia:Reference desk/Archives/Computing/2010 June 12
Computing desk | ||
---|---|---|
< June 11 | << May | June | Jul >> | June 13 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
June 12
editJava layout manager that forces width
editHello! I've been having a problem laying out text components in Java. What I'm trying to do is fill a JPanel with JLabels (which I guess don't technically qualify as "text components" in Java) and JEditorPanes so they all display vertically in the JPanel, one below the other, like a vertical list. I then want to embed the JPanel in a JScrollPane so that the user can scroll down and view all the messages contained in the JLabels and JEditorPanes, but I want to have all these components at a fixed width so that the user doesn't have to scroll sideways (horizontally). JLabels seem to accept this naturally, and wrap their text to the next line and stay within the JPanel's preferred width, but JEditorPanes seem to take advantage of the JPanel and JScrollPane and expand as much as they can to keep their text on the same line. I've been trying to lay out the JPanel with BoxLayout, and I've had a hard time finding a LayoutManager (or even just an idiom in Java, for that matter) that will force all the components in the JPanel to a set width, and let them wrap their text to take as much vertical space (height) as they need. I've tried extending JPanel to implement Scrollable, but I've only had limited success with that, and I'd like a layout technique that could do this even outside of a JScrollPane. Any suggestions? Thank you!--el Aprel (facta-facienda) 01:55, 12 June 2010 (UTC)
- Won't a GridLayout work? The trouble is that will force all your elements to have the same width AND same height. You can use a GridBagLayout, a more enhanced (and complicated) Grid layout. There is a tutorial here. Create a new JPanel pnlList; set it to use a GridLayout or GridBagLayout; add your JLabel and JEditorPanes to pnlList; and then add the single item pnlList to your scroll pane. Nimur (talk) 03:09, 12 June 2010 (UTC)
- Oh, I forgot. Be sure to set a maximum size for pnlList (or whatever panel is being laid out by the GridLayout). Note that only certain layout managers actually respect this setting - but grid and gridbag both should both be compliant. Nimur (talk) 03:20, 12 June 2010 (UTC)
- Well, my problem was my text components were of varying sizes, and GridLayout would take the component with the most text and force all the other components to be as big, right? However, your note about setting the maximum size of the components gave me an idea: use BoxLayout and for all the components, setMaximumSize(MY_DESIRED_WIDTH, Integer.MAX_VALUE) and setAlignmentX(Component.LEFT_ALIGNMENT). It worked surprisingly well. Thank you for the idea, Nimur.--el Aprel (facta-facienda) 02:04, 13 June 2010 (UTC)
Multiple Instances of Ubuntu in Grub Loader
editWhen installing Ubuntu on this machine (dual-boot now), I had two instances of Ubuntu - one 'normal' one and one 'recovery mode' one. Now I've got two of each. The only difference is the number that comes after them. One pair says 2.6.32.22 and the other pair says 2.6.32.21. Why is this, and is there anything I should do about it? --KägeTorä - (影虎) (TALK) 08:37, 12 June 2010 (UTC)
- Those would be different kernels, though I find it pretty surprising that you would have kernels that differ in a fourth-order version number. Probably you don't need to do anything about it unless it annoys you or you're extremely tight on disk space. If it bugs you, you could edit menu.lst (I think it's in /boot/grub ) to remove the entry you don't want, and you could also delete its associated kernel and save a trifling amount of disk. Personally I wouldn't delete the kernel — who knows if the one you keep will get corrupted or something? Plus, if you accidentally deleted the wrong one, you'd be minorly hosed (you'd have to boot from a LiveDisk or something to get menu.lst back to booting the one you still have).
- All this is assuming Grub 1. I don't know how Grub 2 works. --Trovatore (talk) 08:44, 12 June 2010 (UTC)
- Since the question mentions Ubuntu:
#make sure you're running the most up-to-date kernel: uname -a #check if the output contains 2.6.32-22, if not, reboot and select 2.6.32-22 in GRUB's menu.
#This will remove the older kernel and all packages that might belong to it sudo apt-get remove --purge $(dpkg -l linux-image-2.6.32-21*|awk '{print $2}'|grep linux) #If you see a message that you're about to do something stupid, that means the previous command misfired, #then by all means abort! If on the other hand, it simply prompts you "Y/n" to proceed, then hit Y. #This is just for good measure, the previous step should already have triggered it, but doing it twice #doesn't hurt - automatically update the GRUB boot menu sudo update-grub
- The difference is the kernel version number, and it doesn't mean to much to normal users like you and me. Over time, as upgrades happen, it'll accumulate more and more old kernel versions, but there's no harm in keeping them around; they take up a small amount of space, and the consequences of booting into an old kernel are about nil. Paul (Stansifer) 13:15, 12 June 2010 (UTC)
Cheers. If it's not a massively pressing issue I think I'll leave it, then. A quick look at my recent posts will reveal that I'm not having a massive barrel of laughs with a dual-boot system at the moment, so if it's not broken I won't try to fix it. Cheers. --KägeTorä - (影虎) (TALK) 02:01, 13 June 2010 (UTC)
- The old version is keept in the boot meny in the rare case the new kernel does not work on your system.
You should always use the latest if posible since it has been corrected for security problems and/or other bugs. You can see the cange in each version on https://launchpad.net/ubuntu/lucid/+source/linux/+changelog It is rather hard to understand every change but it can be intressting to see. Gr8xoz (talk) 02:07, 14 June 2010 (UTC)
Directory to drive letter
editIs it possible on Windows to map a directory to a drive letter? So for example, "C:\whatever\" would be accessible via "F:\" ? 82.43.89.11 (talk) 13:11, 12 June 2010 (UTC)
- According to this forum discussion, there's a
subst
command for that. Paul (Stansifer) 13:25, 12 June 2010 (UTC)- I don't know what subst is 82.43.89.11 (talk) 14:46, 12 June 2010 (UTC)
- See subst --Rajah (talk) 15:44, 12 June 2010 (UTC)
- I still don't understand. What do I need to to on Windows 7 to make a directory accessible as a drive letter? 82.43.89.11 (talk) 15:52, 12 June 2010 (UTC)
- Open the start menu. Write cmd.exe and press enter. Write
subst F: C:\whatever\
and press enter. Writeexit
and press enter. Done. --Andreas Rejbrand (talk) 17:04, 12 June 2010 (UTC)- If you get a complaint about an incorrect number of parameters, it is because the "subst" command is easily confused by spaces. The fix is to put the desired directory in quotes, like subst y: "c:\Program Files" or the like. Comet Tuttle (talk) 17:23, 12 June 2010 (UTC)
- Thanks this worked perfectly. How do I undo it now? 82.43.90.93 (talk) 19:49, 12 June 2010 (UTC)
- Open the start menu. Write cmd.exe and press enter. Write subst F: /D and press enter. Write exit and press enter. Undone. --Andreas Rejbrand (talk) 20:46, 12 June 2010 (UTC)
- Thanks! 82.43.90.93 (talk) 21:05, 12 June 2010 (UTC)
- Open the start menu. Write cmd.exe and press enter. Write subst F: /D and press enter. Write exit and press enter. Undone. --Andreas Rejbrand (talk) 20:46, 12 June 2010 (UTC)
- Thanks this worked perfectly. How do I undo it now? 82.43.90.93 (talk) 19:49, 12 June 2010 (UTC)
- If you get a complaint about an incorrect number of parameters, it is because the "subst" command is easily confused by spaces. The fix is to put the desired directory in quotes, like subst y: "c:\Program Files" or the like. Comet Tuttle (talk) 17:23, 12 June 2010 (UTC)
- Open the start menu. Write cmd.exe and press enter. Write
- I still don't understand. What do I need to to on Windows 7 to make a directory accessible as a drive letter? 82.43.89.11 (talk) 15:52, 12 June 2010 (UTC)
- See subst --Rajah (talk) 15:44, 12 June 2010 (UTC)
- I don't know what subst is 82.43.89.11 (talk) 14:46, 12 June 2010 (UTC)
- The reciprocal, mapping a disk partition ("drive letter") to a folder, is described on Microsoft TechNet: Assign a mount point folder path to a drive. Nimur (talk) 17:10, 12 June 2010 (UTC)
- I just spent ages trying to work that out then realized it's for the exact opposite of what I want. Thanks anyway it's interesting 82.43.90.93 (talk) 19:47, 12 June 2010 (UTC)
- The subst article links to this GUI tool which you might find helpful. -- BenRG (talk) 22:15, 12 June 2010 (UTC)
- Nice! That's great! 82.43.90.93 (talk) 23:24, 12 June 2010 (UTC)
Mediawiki extension for doing mysql queries from within the wiki
editI remember, but cannot find, an extension for Mediawiki which allows the user to place mysql statements in the source for articles. These statements could query a mysql database (not the same one storing the wiki itself) and generate dynamic pages based on the results. Can anyone point me to an extension or how to do this? Thank you. --Rajah (talk) 14:22, 12 June 2010 (UTC)
Greasemonkey
editHow can I automatically enter a url into a file upload box with greasemonkey? The following works for the description field;
document.getElementsByName("com")[0].value = "Hello";
but when I try for the upload field (one of those little text boxes with "browse" next to it you usually use to navigate to the file)
document.getElementsByName("file")[0].value = "C:\123.jpg";
does not work. 82.43.89.11 (talk) 15:09, 12 June 2010 (UTC)
- Don't you need to escape that slash, like value = "C:\\123.jpg"; ? -- Finlay McWalter • Talk 15:16, 12 June 2010 (UTC)
You can't do that; this is a security restriction. Details here http://www.irt.org/script/1154.htm Arloz (talk) 15:23, 12 June 2010 (UTC)
- Crap. Is there any way to override this restriction on Firefox? 82.43.89.11 (talk) 15:40, 12 June 2010 (UTC)
- Since you're already scripting, circumvent the form and simply create a POST command to the upload script. You can read our article on POST (HTTP) to learn about this. What you want to do is check the form's submit action (it will be called "action" in the HTML source); and then POST your file to that URI. Essentially, instead of using the graphical web form, you will bypass that GUI and just run your script to send the data directly to the server. Nimur (talk) 17:13, 12 June 2010 (UTC)
- I think it should be made clear, though, that you cannot do this in Javascript, or from any kind of browser-side scripting alone (and the reasons for this are fairly obvious, as if you could use Javascript to get a computer to cough up files automatically, that would make open up a MASSIVE security hole). You'll have to do this with something like PHP or Perl or so on. It's kind of a different beast, and I don't know how compatible it is with greasemonkey (though if greasemonkey can be made to open local PHP files, then it could be done pretty easily, if you know PHP). If you are using PHP, I highly recommend using something like Snoopy which will make creating a well-formed POST command a lot easier than just doing it from scratch. --Mr.98 (talk) 17:58, 12 June 2010 (UTC)
- I don't think I know enough php to do anything this technical. I'm surprised there isn't a way to override whatever restrictions are in place on Firefox and get it to enter some text into a text box though. Surely there's some way to hack that. 82.43.90.93 (talk) 19:28, 12 June 2010 (UTC)
- Surely there is, but it's probably non-trivially difficult (harder than just learning the relevant PHP, which is really not that complicated if you do it through Snoopy). It probably requires you to change how Firefox handles Javascript, which probably involves recompiling the whole thing. That's a lot harder than getting PHP set up on your system, writing a PHP function that spits a file at a given website, and then having Greasemonkey run the PHP script whenever you want. --Mr.98 (talk) 21:44, 12 June 2010 (UTC)
- Ok, thanks. Well anyway I found iMacros which does what I want. Thanks everyone 82.43.90.93 (talk) 21:57, 12 June 2010 (UTC)
- Surely there is, but it's probably non-trivially difficult (harder than just learning the relevant PHP, which is really not that complicated if you do it through Snoopy). It probably requires you to change how Firefox handles Javascript, which probably involves recompiling the whole thing. That's a lot harder than getting PHP set up on your system, writing a PHP function that spits a file at a given website, and then having Greasemonkey run the PHP script whenever you want. --Mr.98 (talk) 21:44, 12 June 2010 (UTC)
- I don't think I know enough php to do anything this technical. I'm surprised there isn't a way to override whatever restrictions are in place on Firefox and get it to enter some text into a text box though. Surely there's some way to hack that. 82.43.90.93 (talk) 19:28, 12 June 2010 (UTC)
- I think it should be made clear, though, that you cannot do this in Javascript, or from any kind of browser-side scripting alone (and the reasons for this are fairly obvious, as if you could use Javascript to get a computer to cough up files automatically, that would make open up a MASSIVE security hole). You'll have to do this with something like PHP or Perl or so on. It's kind of a different beast, and I don't know how compatible it is with greasemonkey (though if greasemonkey can be made to open local PHP files, then it could be done pretty easily, if you know PHP). If you are using PHP, I highly recommend using something like Snoopy which will make creating a well-formed POST command a lot easier than just doing it from scratch. --Mr.98 (talk) 17:58, 12 June 2010 (UTC)
DownThemAll!
editCan anyone explain how to do what I want in the following situation please? I have not been able to find any explainastion online.
There is a webpage with links to a series of files on it: file1.zip, file2.zip....file9.zip. I right click on file1.zip and select DownThemAll! from the menu. What do I do next to get it to download all these zip files but nothing else please? All I've managed to do is to download file1.zip to the directory I choose, and a lot of unwanted gif and html files seem to have been downloaded to some unknown location on my HD. Thanks 92.15.0.254 (talk) 18:28, 12 June 2010 (UTC)
- After clicking "DownThemAll!" from the menu, click "Filters" then click "Archives". Or type in "*.zip" under "Fast filtering". --Mr.98 (talk) 19:01, 12 June 2010 (UTC)
- If you want to be doubly sure you could also do something like file[1:9].zip as the filter. Findstr (talk) 12:55, 15 June 2010 (UTC)
Annoying Pop-Down Toolbar on Google Chrome
editI keep getting a little pop-down toolbar everytime I visit a website in a different language on Google Chrome. It's annoying because it takes around a second (or maybe just a little bit less) to appear, making the page itself move down a centimetre or so, and very often causing me to click on something I didn't want to click on (due the the page moving). Is there any way to switch it off completely? It gives me the option to not translate that particular page or that particular language, but really I'd rather just get rid of it completely. Cheers. --KägeTorä - (影虎) (TALK) 19:30, 12 June 2010 (UTC)
- It's OK. I managed it. --KägeTorä - (影虎) (TALK) 20:24, 12 June 2010 (UTC)
Ubuntu WiFi
editI'm trying to connect a computer running Ubuntu 9.10 to my home wifi network. My Linksys wireless-B adapter works well enough to detect pretty much every network on my block, but I can't get authentication from my router (which is wireless-G, but that never stopped a Windows PC from using the same adapter to connect).
I've tried 64-bit WEP, 128-bit WEP, and WPA Personal encryption methods as well as two different wifi managers (the default Network Manager and something called WICD). The SSID is being broadcast. The process stalls when it gets to "waiting for authentication" (in WICD, as I haven't found a way to view Network Manager's connection status).
The encryption key is fine, since I can get a Wii and a Nintendo DS to connect just fine. I've triple-checked the key I'm putting in several times over again.
Any help or advice would be great. Multiple Google searches haven't turned up anything that A. I know how to do and B. works. Aylad ['ɑɪlæd] 23:21, 12 June 2010 (UTC)
- I'll assume this is a laptop or netbook. This is most likely a driver issue. I had same issues with a Dell laptop. You need to google or tell us your manufacturer/model. --Rajah (talk) 01:01, 13 June 2010 (UTC)
- I suggest you take a look at H.J. Heins' excellent website if you haven't already. It's probably the most authoritative source on native Linux Wi-Fi. If the card is listed "green" (native support), then we most likely have some sort of driver issue as Rajah has said. "Yellow" cards (partial/inconsistent support) usually have additional instructions -- for example, some "yellow" cards require you to download firmware or a closedsource driver -- that we can help you follow. "Red" cards often require Ndiswrapper. Take a look also at Ubuntu's WifiDocs. If your card is listed there, there may be more Ubuntu-specific instructions for you to follow. Good luck. Xenon54 (talk) 01:48, 13 June 2010 (UTC)
- Rajah: it's actually an old Compaq desktop. The wireless adapter is a USB device. I should have said that earlier.
- Xenon: thanks. The first site you recommended says that for my wireless adapter (under Linksys, WUSB11 v2.8), "Driver included in mainline kernel since 2.6.24, replaced with at76c50x-usb (mac80211 port) in 2.6.30. Firmware is required, available from http://www.thekelleys.org.uk/atmel/ ". Unfortunately, I have no idea which file(s) to download or what to do next. I've never really worked with this sort of thing in Linux. Aylad ['ɑɪlæd] 13:31, 13 June 2010 (UTC)
- You probably want to download http://www.thekelleys.org.uk/atmel/atmel-firmware-1.3.tar.gz then and install it. (untar it, configure, make, install : http://www.cyberciti.biz/faq/install-tarballs/ ) You may need to use
sudo
before "make install". --Rajah (talk) 14:16, 13 June 2010 (UTC)- This tarball is actually different from most. Just extract the files with tar or whatever program you like, then in a terminal window cd to the newly created directory (titled "atmel-firmware-1.3" or similar) and run "sh install.sh". Xenon54 (talk) 14:37, 13 June 2010 (UTC)
- You probably want to download http://www.thekelleys.org.uk/atmel/atmel-firmware-1.3.tar.gz then and install it. (untar it, configure, make, install : http://www.cyberciti.biz/faq/install-tarballs/ ) You may need to use
- I suggest you take a look at H.J. Heins' excellent website if you haven't already. It's probably the most authoritative source on native Linux Wi-Fi. If the card is listed "green" (native support), then we most likely have some sort of driver issue as Rajah has said. "Yellow" cards (partial/inconsistent support) usually have additional instructions -- for example, some "yellow" cards require you to download firmware or a closedsource driver -- that we can help you follow. "Red" cards often require Ndiswrapper. Take a look also at Ubuntu's WifiDocs. If your card is listed there, there may be more Ubuntu-specific instructions for you to follow. Good luck. Xenon54 (talk) 01:48, 13 June 2010 (UTC)
- When I run "sh install.sh" I get an error message about needing to get an up-to-date hotplug system. I don't know how to do that. There is no /etc/hotplug directory where I'm supposed to find the firmware.agent file. There's another option in the readme about using some sort of script before the interface loads, but (guess what?) I don't know how to do that, either. Feeling very much like a noob now... Aylad ['ɑɪlæd] 03:46, 14 June 2010 (UTC)