How can I make the combo box turn to the value of black.
When the show button is pressed (and not before), a filled black square should be
displayed in the display area. The combo box (or drop down list) that enables the user to choose the colour of
the displayed shape and the altering should take effect immediately.When the show button is pressed,
the image should immediately revert to the black square, the combo box should show the value that
correspond to the black.
Now ,the problem is: after I pressed show button, the image is reverted to the black square,but I don't know
how can I make the combo box turn to the value of black.
Any help or hint?Thanks a lot!
coding 1.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class test extends JFrame {
private JPanel buttonPanel;
private DrawPanel myPanel;
private JButton showButton;
private JComboBox colorComboBox;
private boolean isShow;
private int shape;
private boolean isFill=true;
private String colorNames[] = {"black", "blue", "cyan", "darkGray", "gray",
"green", "lightgray", "magenta", "orange",
"pink", "red", "white", "yellow"}; // color names list in ComboBox
private Color colors[] = {Color.black, Color.blue, Color.cyan, Color.darkGray,
Color.gray, Color.green, Color.lightGray, Color.magenta,
Color.orange, Color.pink, Color.red, Color.white, Color.yellow};
public test() {
super("Draw Shapes");
// creat custom drawing panel
myPanel = new DrawPanel(); // instantiate a DrawPanel object
myPanel.setBackground(Color.white);
// set up showButton
// register an event handler for showButton's ActionEvent
showButton = new JButton ("show");
showButton.addActionListener(
// anonymous inner class to handle showButton events
new ActionListener() {
// draw a black filled square shape after clicking showButton
public void actionPerformed (ActionEvent event) {
// call DrawPanel method setShowStatus and pass an parameter
// to decide if show the shape
myPanel.setShowStatus(true);
isShow = myPanel.getShowStatus();
shape = DrawPanel.SQUARE;
// call DrawPanel method setShape to indicate shape to draw
myPanel.setShape(shape);
// call DrawPanel method setFill to indicate to draw a filled shape
myPanel.setFill(true);
// call DrawPanel method draw
myPanel.draw();
myPanel.setFill(true);
myPanel.setForeground(Color.black);
}// end anonymous inner class
);// end call to addActionListener
// set up colorComboBox
// register event handlers for colorComboBox's ItemEvent
colorComboBox = new JComboBox(colorNames);
colorComboBox.setMaximumRowCount(5);
colorComboBox.addItemListener(
// anonymous inner class to handle colorComboBox events
new ItemListener() {
// select shape's color
public void itemStateChanged(ItemEvent event) {
if(event.getStateChange() == ItemEvent.SELECTED)
// call DrawPanel method setForeground
// and pass an element value of colors array
myPanel.setForeground(colors[colorComboBox.getSelectedIndex()]);
myPanel.draw();
}// end anonymous inner class
); // end call to addItemListener
// set up panel containing buttons
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(4, 1, 0, 50));
buttonPanel.add(showButton);
buttonPanel.add(colorComboBox);
JPanel radioButtonPanel = new JPanel();
radioButtonPanel.setLayout(new GridLayout(2, 1, 0, 20));
Container container = getContentPane();
container.setLayout(new BorderLayout(10,10));
container.add(myPanel, BorderLayout.CENTER);
container.add(buttonPanel, BorderLayout.EAST);
setSize(500, 400);
setVisible(true);
public static void main(String args[]) {
test application = new test();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
coding 2
import java.awt.*;
import javax.swing.*;
public class DrawPanel extends JPanel {
public final static int CIRCLE = 1, SQUARE = 2;
private int shape;
private boolean fill;
private boolean showStatus;
private int shapeSize = 100;
private Color foreground;
// draw a specified shape
public void paintComponent (Graphics g){
super.paintComponent(g);
// find center
int x=(getSize().width-shapeSize)/2;
int y=(getSize().height-shapeSize)/2;
if (shape == CIRCLE) {
if (fill == true){
g.setColor(foreground);
g.fillOval(x, y, shapeSize, shapeSize);
else{
g.setColor(foreground);
g.drawOval(x, y, shapeSize, shapeSize);
else if (shape == SQUARE){
if (fill == true){
g.setColor(foreground);
g.fillRect(x, y, shapeSize, shapeSize);
else{
g.setColor(foreground);
g.drawRect(x, y, shapeSize, shapeSize);
// set showStatus value
public void setShowStatus (boolean s) {
showStatus = s;
// return showstatus value
public boolean getShowStatus () {
return showStatus;
// set fill value
public void setFill(boolean isFill) {
fill = isFill;
// set shape value
public void setShape(int shapeToDraw) {
shape = shapeToDraw;
// set shapeSize value
public void setShapeSize(int newShapeSize) {
shapeSize = newShapeSize;
// set foreground value
public void setForeground(Color newColor) {
foreground = newColor;
// repaint DrawPanel
public void draw (){
if(showStatus == true)
repaint();
Hello,
does setSelectedIndex(int anIndex)
do what you need?
See Java Doc for JComboBox.
Similar Messages
-
How can we make the value of pricing condition flow to the sales invoice?
At an intercompany process, we have the condition type PBXX at the purchase order. On the other hand, at the sales invoice (which is created by VF01) of the sames process, there exists the condition type PR00. The calue of the condition types PBXX and PR00 should be the same. How can we make the value of PBXX flow to the sales invoice? I can create new pricing procedures if needed. I can change the types of the pricing conditions (such as PBXX or PR00) included at the procedures (by customization) if needed. All I need is to have the value of the price at the purchase order the same with the sales invoice at the same process. The transaction codes used at this process are:
ME21N - Create purchase order
VL10D - Create delivery
VF01 - Create invoice
Thanks in advance for the answers...Yes, i verified that the config item id in the pricing table and the cz_config_items table are the same (once we save the configuration).
The reason we have to do this is coz I have to pass additional parameters, which are item speciific (captured at confiugurator runtime session) while making a call to the pricing engine.
Hence, we are capturing some additional pricing parameters (during a runtime configurator session) in a custom table, and plan to link those to the corresponding items in the 'CZ_Pricing_Structure' table thru the config_item_id. -
I have 2 combo boxes If I have data table like below
TableA
ID NAME
1 A
2 B
3 C
4 A
I make "TableA" as data source of "combobbox1" and "combobox2" like
combobox1.datasource = TableA
combobox1.displaymember = "ID"
combobox2.datasource = TableA
combobox2.displaymember = "Name"
I want when combobox2 select index at "A" , Combobox1 show only the items at ID = 1 And ID = 4
ThanksThis is not actually a question to be posted in SQL Server. Here is a link for ASP.NET forum.
http://forums.asp.net/
It looks like there is a filter that can be applied in .NET dataset and populate the results in your combobox1. You may get better help from .NET forums for this question. -
How can I make the Label go on top of the Text box?
How can I make the Label go on top of the Text box?
Thanks again,
DougSet the Label Horizontal / Vertical Alignment property for the textarea to Above.
-
How can I make a gray box or gray screen in Pages over a few lines of text?
How can I make a gray box or gray screen in Pages over a few lines of text?
Thanks. Almost what I was looking for.
While that makes for a gray over the lines, it still does not form a box.
Any other suggestions to form a solid rectangular gray box? -
I have moved my library to an external hard drive and changed the location of the iTunes media folder in Preferences, but every time I close and re-open iTunes, I have to do it all over again. How can I make the iTunes media folder change permanent? I have an older machine with Windows XP.
I don't believe mounting the hard drive should be necessary, unless you have several external drives and want your computer to recognise them as folders, rather than drives. I've never had to mount a hard drive, ever. If you don't know how to do it, then it shouldn't be necessary now.
Try this:
Prepare iTunes so that it can see the external drive.
Make a note of which drive-letter the external drive has been allocated. (Look in Windows Exploer)
Look at the file location for a song. Make sure it plays (and therefore that iTunes has found it). Highlight it and select File/Get Info/Summary>Where: and make a note of the drive letter for that song.
Close and shut down the computer.
The next time you turn the computer on again, connect the external drive
Before you start iTunes - check the external drive in Windows Explorer. Is it ready, does it have the same drive-letter that it had last time? Can you go into the drive and see the files on it?
Once you can, start iTunes. (If the drive lettter has changed, you need to work out why before going any further.)
If iTunes fails to find your external drive, you need to check where iTunes is looking for your Library.
Select the same song you checked before (presumably iTunes can no longer find it). Follow the procedure for locating it. You should be able to see where iTunes thinks the file is. It's the drive that counts. Which drive letter is iTunes looking at? Is it the same one that it was previously (which should also be the same one that the drive has now).
What happens, which step do you have problems with?
Message was edited by: the fiend -
I have a new iPhone 5C, have the sounds alerts set up. But I'm not getting sound alerts for new voicemail, only the red circle on the screen. How can I make the sound alert work?
I have had this same problem for weeks now with my 4S. I just got a new 5S after being extremely frustrated and the same thing - no sounds. After searching posts all over, I couldn't find a solution. I just told my friend of the issue and he asked "Do you have the Do Not Distrub on?" I didn't even know such a function existed. Upon looking that was exactly the issue.
To resolve, go to Settings> Do Not Disturb> Manual. If it is green, turn it off. You will now get phone calls and text alerts.
This functionality is also on your quick access utility menu (slide up menu). I assume this is how it was enabled on my phone.
I will post on other sites since I searched for weeks for this solution and didn't see it anywhere. Good luck! -
How can i make the text bigger?
How can i make the text bigger?
1. press "T" to bring up the text tool.
2. click the text you want to edit
3. highlight the text you want to change size with your cursur
4. If it's not already up, press Command + T to bring up the text tool box and adjust the size under the character group. The value you want to change will have a "TT" next to it.
If this doesn't help. More details will help us help you. -
How can i make the text go vertically in numbers
How can I make the text vertical in numbers? I have merged the cells and cannot find an option for making it go vertical as opposed to horizontal.
I already gave two tools to fit this kind of needs.
tip #1 :
--{code}
--[SCRIPT write_vertically]
Enregistrer le script en tant que Script : write_vertically.scpt
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Utilisateurs:<votreCompte>:Bibliothèque:Scripts:Applications :Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Saisir dans une cellule le mot à écrire verticalement puis le sélectionner.
ATTENTION, il ne faut pas sélectionner la cellule mais le mot qui doit apparaitre surligné.
Aller au menu Scripts , choisir Numbers puis choisir “write_vertically”
Le script colle dans la cellule le mot apès avoir inséré un return entre tous les caractères.
Pour mon usage personnel j'associe un raccourci à ce script grace à FastScripts.
--=====
L’aide du Finder explique:
L’Utilitaire AppleScript permet d’activer le Menu des scripts :
Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case “Afficher le menu des scripts dans la barre de menus”.
Sous 10.6.x,
aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript
puis cocher la case “Afficher le menu des scripts dans la barre des menus”.
--=====
Save the script as a Script: write_vertically.scpt
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
In a cell, type a word to write vertically then select it.
CAUTION, don’t select the cell but the word which must be highlighted.
Go to the Scripts Menu, choose Numbers, then choose “write_vertically”
The script insert in the cell the word after inserting a return between every characters.
For my own use, I link a shortcut to the script thank to FastScripts.
--=====
The Finder’s Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the “Show Script Menu in menu bar” checkbox.
Under 10.6.x,
go to the General panel of AppleScript Editor’s Preferences dialog box
and check the “Show Script menu in menu bar” option.
--=====
Yvan KOENIG (VALLAURIS, France)
2011/12/17
2012/01/01 no longer use a local variable, use result
--=====
on run
Clear the clipboard *)
set the clipboard to ""
Copy the selection in the clipboard *)
my raccourci("Numbers", "c", "c")
Loop waiting that the clipboard is really filled *)
repeat
try
if (the clipboard as text) is not "" then exit repeat
on error
end try
end repeat
Extract the clipboard's content *)
the clipboard as text
Insert return between every characters *)
my recolle(every character of result, return)
Fill the clipboard with the edited string *)
set the clipboard to result
Paste in the cell *)
my raccourci("Numbers", "v", "cas")
end run
--=====
on recolle(l, d)
local oTIDs, t
set oTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
--=====
on activateGUIscripting()
(* to be sure than GUI scripting will be active *)
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true
end tell
end activateGUIscripting
--=====
==== Uses GUIscripting ====
This handler may be used to 'type' text, invisible characters if the third parameter is an empty string.
It may be used to 'type' keyboard raccourcis if the third parameter describe the required modifier keys.
I changed its name « shortcut » to « raccourci » to get rid of a name conflict in Smile.
on raccourci(a, t, d)
local k
tell application a to activate
tell application "System Events" to tell application process a
set frontmost to true
try
t * 1
if d is "" then
key code t
else if d is "c" then
key code t using {command down}
else if d is "a" then
key code t using {option down}
else if d is "k" then
key code t using {control down}
else if d is "s" then
key code t using {shift down}
else if d is in {"ac", "ca"} then
key code t using {command down, option down}
else if d is in {"as", "sa"} then
key code t using {shift down, option down}
else if d is in {"sc", "cs"} then
key code t using {command down, shift down}
else if d is in {"kc", "ck"} then
key code t using {command down, control down}
else if d is in {"ks", "sk"} then
key code t using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
key code t using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
key code t using {command down, shift down, option down}
end if
on error
repeat with k in t
if d is "" then
keystroke (k as text)
else if d is "c" then
keystroke (k as text) using {command down}
else if d is "a" then
keystroke k using {option down}
else if d is "k" then
keystroke (k as text) using {control down}
else if d is "s" then
keystroke k using {shift down}
else if d is in {"ac", "ca"} then
keystroke (k as text) using {command down, option down}
else if d is in {"as", "sa"} then
keystroke (k as text) using {shift down, option down}
else if d is in {"sc", "cs"} then
keystroke (k as text) using {command down, shift down}
else if d is in {"kc", "ck"} then
keystroke (k as text) using {command down, control down}
else if d is in {"ks", "sk"} then
keystroke (k as text) using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
keystroke (k as text) using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
keystroke (k as text) using {command down, shift down, option down}
end if
end repeat
end try
end tell
end raccourci
--=====
--[/SCRIPT]
--{code}
tip #2 :
--{code}
--[SCRIPT rotate_cell_contents]
Enregistrer le script en tant que Script : rotate_cell_contents.scpt
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Sélectionner une cellule dont le texte doit être tourné de 90 degrés.
Aller au menu Scripts , choisir Numbers puis choisir “rotate_cell_contents”
--=====
L’aide du Finder explique:
L’Utilitaire AppleScript permet d’activer le Menu des scripts :
Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case “Afficher le menu des scripts dans la barre de menus”.
Sous 10.6.x,
aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript
puis cocher la case “Afficher le menu des scripts dans la barre des menus”.
--=====
Save the script as a Script: rotate_cell_contents.scpt
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
Select a cell whose contents must be rotated for 90 degrees.
Go to the Scripts Menu, choose Numbers, then choose “rotate_cell_contents”
--=====
The Finder’s Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the “Show Script Menu in menu bar” checkbox.
Under 10.6.x,
go to the General panel of AppleScript Editor’s Preferences dialog box
and check the “Show Script menu in menu bar” option.
--=====
Yvan KOENIG (VALLAURIS, France)
2011/06/23
2011/06/26 -- No longer use an auxiliary text box. Now keep the text attributes.
2012/01/31 -- edited for Lion
--=====
on run
local dName, sName, tName, rowNum1, colNum1, rowNum2, colNum2
local le_texte, la_largeur, la_hauteur, myNewDoc
my activateGUIscripting()
Extract properties of the source/target cell *)
set {dName, sName, tName, rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
set selection range to range (name of column colNum1 & name of row rowNum1)
end tell
Cut*)
my raccourci("Numbers", "x", "c")
Trigger Preview *)
tell application "System Events"
if "Preview" is not in (name of every application process) then launch application "Preview"
end tell
delay 0.2 -- required
New document from the clipboard *)
my raccourci("Preview", "n", "c")
Rotate to left *)
my raccourci("Preview", "l", "c")
Copy *)
my raccourci("Preview", "c", "c")
Quit *)
my raccourci("Preview", "q", "c")
(system attribute "sys2") < 7
if result then
Click the [Don't Save] button in the warning sheet *)
tell application "Preview" to activate
tell application "System Events" to tell application process "Preview" to tell window 1
name of buttons
repeat 50 times
delay 0.1
if exists sheet 1 then exit repeat
end repeat
tell sheet 1 to click button 2
end tell
end if
Back to Numbers *)
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
-- just reset the focus on the table
end tell
Paste in the cell *)
my raccourci("Numbers", "v", "c")
end run
--=====
set { dName, sName, tName, rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
on get_SelParams()
local d_name, s_name, t_name, row_num1, col_num1, row_num2, col_num2
tell application "Numbers" to tell document 1
set d_name to its name
set s_name to ""
repeat with i from 1 to the count of sheets
tell sheet i to set maybe to the count of (tables whose selection range is not missing value)
if maybe is not 0 then
set s_name to name of sheet i
exit repeat
end if -- maybe is not 0
end repeat
if s_name is "" then
if my parleAnglais() then
error "No sheet has a selected table embedding at least one selected cell !"
else
error "Aucune feuille ne contient une table ayant au moins une cellule sélectionnée !"
end if -
How can I make the rolumn and row headers appear on the printed sheet?
I am working in Numbers'09. I want to print out my chart with the column letters and row numbers showing.
How can I make the rolumn and row headers appear on the printed sheet?g,
Those annotations are called "Labels", and they are only visible during editing when a cell selection is made within the table. If you need to have the labels on your final output, you can create labels in Text Boxes and position them adjacent to the table.
Jerry -
How can I make the skin like rock ?
How can I make the skin of a dramatic BW image of a Boxer look like peeling lava skin ? I know that's a funny way to say it, but I want to make him look like rock and lava with hard cracks and such. Anyone have some ideas ?
I'm sorry Myron, I didn't mean to cause your thread to go in the wrong direction. I was feeling a bit frisky after a long day.
Making skin look like something else is not a task I do normally, but if I were to want to experiment I'd probably try things like pasting a section of rock over the top of the skin in question, then set the mixing mode to Luminosity (so that just the luminance of the rock surface is used with the color of the face. Use masking and partial mixing to help blend it.
Seek (or capture) rock imagery with the light coming from the same direction, and with a similar level of detail. That will help make it seem more believable.
There may be others (I hope) who will chime in with more specific instructions or other tricks o' the trade that they've found to work.
Best of luck, and please don't be afraid to show your results.
-Noel -
How can I make the "Enable to sink files" warning to go away?
How can I make the "Enable to sink files" warning to go away?
Hi Airmiranda
The following doc should help: http://helpx.adobe.com/creative-cloud/kb/creative-cloud-files-wont-connect.html
"If you are using Creative Cloud Connection preview, you will either see “Unable to sync file(s)” or “Unable to connect...” errors. To disable these error alerts, you can Turn Sync Off or Quit Creative Cloud Connection."
Thanks
Bev -
How can I make a check box active ONLY if another check box is activated?
How can I make a check box active ONLY if another check box is activated?
I have an editable PDF for a client, which contains text fields and check box fields.
There are three main check boxes (let's call them A, B and C) that the user is required to choose from, and I have given all three the same name in the Name tab of the General tab menu but different export values in order that ONLY one of the boxes can be checked at any time. Ticking one will deactivate another if it is already checked, etc.
However, I then have a further two check boxes which I wish to become available ONLY if the second one of the above three boxes is checked. Other than that I do not wish the user to have access to them.
I'm guessing it requires some kind of Action Script or Javascript, which is not my forté! Any help would be much appreciated.
Regards
TonySee Disabling (graying-out) Form Fields by Thom Parker. It covers both Acrobat and LiveCycle forms.
-
I down loaded sygic on my iPhone 3s but the icon is missing even in the search but when I want to download it again ,it say this application is present, how can I make the icon to show up
- Have you tried a reset. Nothing is lost
Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
least ten seconds, until the Apple logo appears.
- Try syncing the iPod to your computer. Then delete from iTunes and sync. that should delete it from the iPod. Then redownload it. -
Macbook Pro with OSX Yosemite: I am frustrated that when using Word for Mac, the cursor keeps jumping around all over the page. How can I make the pointer follow the cursor so this stops?
Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
* Don't make any changes on the Safe mode start window.
See:
* [[Troubleshooting extensions and themes]]
Maybe you are looking for
-
Error (-600) drive with Logic files no longer mounting.
Greetings fellow sufferers. A brief history pre my latest disaster. PSU and logic board died on me last week after 6 years of constant continuous faithful service. Bought a second hand power mac took out hard drives and RAM and replaced them with min
-
Need your help on performance issue please
Hello everyone! I need your help to understand an effect I notice with a Thread class I built. I currently work on enhancement of my application Playlist Editor (see http://www.lightdev.com/page74.htm) and a new release will be available soon. Among
-
Help! I have 2 problems related to iPhoto: 1: I accidentally ran iPhoto Library Upgrader on my Picture folder and now I have to right click on it to "show contents" instead of double clicking on it and looking at it in Finder. I cannot figure out
-
Importing/Exporting - I am no man of international business - Blerg
When I import photos from my camera (Canon Power Shot S5) into iPhoto they automatically turn to .jpegs. This is no problem when I view them on the Mac, however, they remain such when I export them to a flash drive. When I take the flash drive to the
-
Fingerprint scanner loads slowly during bootup
I've noticed that during windows 7 startup, when the logon screen pops up, and the fingerprint reader begins to initialize, it takes it quite a while before it's actually "ready to scan". The same thing occurs when waking up from hibernation or sleep