Setting selected border colour of a JToggleButton
Hi
I am wanting to be able to change the selected border colour of a JToggleButton. I have already been able to do a similar thing for changing the selected background colour for the JToggleButton by:
button.setUI(new MyUI(Color.gray));
class MyUI extends javax.swing.plaf.metal.MetalToggleButtonUI
Color color;
public MyUI(Color c){color = c;}
public Color getSelectColor(){return color;}
however I want the background colour of the toggle button to remain the same whether selected or not (so I'm not using this).
I realise that I can use a MouseListener to do this (I have already done that to change the rollover border colour), but it is more of a pain for the selected border colour, so I was wondering if anyone knew of a similar way to change the selected border colour to the above method?
Thanks
your layerpane lives on top of a container. set the
background of the container.
here is a sample code. In the createAndShowGUI you
can add a line,
frame.setBackground(Color.white) ;
http://java.sun.com/docs/books/tutorial/uiswing/compon
ents/example-1dot4/LayeredPaneDemo2.javaThe program uses JLabels on different layers to display the colours, I would prefer not to use a large white JLabel as my background.
I have tried to set my JFrame background colour using-
frame.setBackground(Color.white) ;It will not work for me
Similar Messages
-
JTextPane - setting selected text colour
Ok, I have a bit of a problem. Here is some general information about my program.
I have a JTextPane called "DDITextArea" and I can type in it and stuff. I want to be able to select some of the text and use a JColorChooser to set the text to that color of my choice. I am doing a bit of experimentation with the swing components and messed around with a JColorChooser. Here is the code for the chooser.
ColourOption.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (first) {
first = false;
chooser.setPreviewPanel(new CustomPane());
JDialog dialog = JColorChooser.createDialog(RecipeBrowser.this, "Demo 3", true, chooser, new ActionListener() {
public void actionPerformed(ActionEvent e) {
c = chooser.getColor();
}, null);
dialog.setVisible(true);
*I NEED SOMETHING HERE TO SET THE SELECTED TEXT TO THE COLOUR I CHOOSE WITH THE JCOLOURCHOOSER
*I HAVE A JTEXTPANE AND I WANT TO BE ABLE TO SELECT SOME TEXT THEN USE THE JCOLORCHOOSER TO SET THE COLOUR OF THE SELECTED TEXT
});as you can see from the comments near the end of the code sample, I need to know how to set the selected text to Color c. I don't know if there is a method for this. I looked at the online Java syntax database but to no luck. Just to ensure that there is no misunderstanding I will give an example:
DDITextArea has the sentence "The dog is wet and smelly" and its default font colour is black. If I highlight the words "The Dog", open the ColorChooser and select red, the words "The Dog" will be red while everything else is black.
If it is any help, here is where my DDITextArea is created
final JTextPane DDITextArea = new JTextPane();
JScrollPane DDITextAreaScrollPane = new JScrollPane(DDITextArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
//DDITextArea.setLineWrap(true);
//DDITextArea.setWrapStyleWord(true);
DDITextArea.setEnabled(true);
DDITextArea.setEditable(true);
DDITextArea.setVisible(true);
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridx = 1;
gbc.gridy = GridY;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 1;
gbc.weighty = 1;
gbl.setConstraints(DDITextAreaScrollPane, gbc);
PrintTab.add(DDITextAreaScrollPane);Am I missing any necessary syntax to do this or is there something much more complicated involved?Sorry for the double post but I figured it out. I missed the answer. This is a clear sign I must stop doing past-midnight research.
Anyways, for any folds that have trouble with this in the future, here you go. I hope someone, somewhere, sometime, will have need for this.
ColourOption.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (first) {
first = false;
chooser.setPreviewPanel(new CustomPane());
JDialog dialog = JColorChooser.createDialog(RecipeBrowser.this, "Demo 3", true, chooser, new ActionListener() {
public void actionPerformed(ActionEvent e) {
c = chooser.getColor();
}, null);
dialog.setVisible(true);
//THE CODE BELOW THIS COMMENT IS WHAT I ADDED
new StyledEditorKit.ForegroundAction("", c).actionPerformed(null);
//THE CODE ABOVE THIS COMMENT IS WHAT I ADDED
}); -
How do I change a default from feathered edge to sharp edge when I select a path?
I'm working in Photoshop CS6 on a Mac and am having trouble when I select a Path it automatically feathers the selection border. I can't seem to find any place to adjust a feather setting. Does anyone have a suggestion? I'm using paths to silhouette an image on a photograph to use in another document and I need a hard edge on it, not a feathered one.In the Paths panel, click the flyout menu (in the top right of the panel) and choose Make Selection (this option will only be available if you have a path selected). Reduce the Feather Radius to 0 (zero) and click OK. This setting will be the default even when clicking the Load Path as Selection button.
-
WebUtil and Microsoft Excel: Setting cell border properties
I'm using the CLIENT_OLE2 package shipped with WebUtil to create a Microsoft Excel spreadsheet from an Oracle 10g Form and, so far, have managed to:
- Create multiple worksheets
- Populate cells with values and formulae
- Format cells, including setting font name and size, setting bold italic and underline attributes
The final requirement is to set a border on a cell or group of cells, but this is where I'm stumped. My code thus far looks like this:
DECLARE
l_application CLIENT_OLE2.OBJ_TYPE ;
l_workbooks CLIENT_OLE2.OBJ_TYPE ;
l_workbook CLIENT_OLE2.OBJ_TYPE ;
l_worksheets CLIENT_OLE2.OBJ_TYPE ;
l_worksheet CLIENT_OLE2.OBJ_TYPE ;
l_cell CLIENT_OLE2.LIST_TYPE ;
l_borders CLIENT_OLE2.OBJ_TYPE ;
BEGIN
l_application := CLIENT_OLE2.CREATE_OBJ('Excel.Application') ;
l_workbooks := CLIENT_OLE2.GET_OBJ_PROPERTY(l_application,'Workbooks') ;
l_workbook := CLIENT_OLE2.GET_OBJ_PROPERTY(l_workbooks,'Add') ;
l_worksheets := CLIENT_OLE2.GET_OBJ_PROPERTY(l_workbook,'Worksheets') ;
l_arguments := CLIENT_OLE2.CREATE_ARGLIST ;
CLIENT_OLE2.ADD_ARG(l_arguments,'Sheet1') ;
l_worksheet := CLIENT_OLE2.GET_OBJ_PROPERTY(l_workbook,'Worksheets',l_arguments) ;
CLIENT_OLE2.DESTROY_ARGLIST(l_arguments) ;
-- Select cell A1
l_arguments := CLIENT_OLE2.CREATE_ARGLIST ;
CLIENT_OLE2.ADD_ARG(l_arguments,1) ;
CLIENT_OLE2.ADD_ARG(l_arguments,1) ;
l_cell := CLIENT_OLE2.GET_OBJ_PROPERTY(l_worksheet,'Cells',l_arguments) ;
CLIENT_OLE2.DESTROY_ARGLIST(l_arguments) ;
l_borders := CLIENT_OLE2.GET_OBJ_PROPERTY(p_cells,'Borders') ;
-- What happens next...?
-- Clean up
CLIENT_OLE2.RELEASE_OBJ(l_borders) ;
CLIENT_OLE2.RELEASE_OBJ(l_worksheet) ;
CLIENT_OLE2.RELEASE_OBJ(l_worksheets) ;
CLIENT_OLE2.RELEASE_OBJ(l_workbook) ;
CLIENT_OLE2.RELEASE_OBJ(l_workbooks) ;
CLIENT_OLE2.RELEASE_OBJ(l_application) ;
END ;I'd be obliged for a pointer in the right direction!Well, in spite of 80-odd views, it looks like I've answered my own question.
The borders around a range of cells in Excel are actually separate elements of the Borders object. You need to specify which border you want and set it individually. The code below draws a border around cells A1 to C3. Note the constants defined at the top of the listing; these are the "actual" values of the corresponding Excel constants that are referenced in the VBA code if you draw the border by hand while recording a macro.
Enjoy!
DECLARE
c_automatic CONSTANT NUMBER := -4105 ; -- ColorIndex = xlAutomatic
c_thin CONSTANT NUMBER := 2 ; -- Weight = xlThin
c_medium CONSTANT NUMBER := -4138 ; -- Weight = xlMedium
c_thick CONSTANT NUMBER := 4 ; -- Weight = xlThick
c_continuous CONSTANT NUMBER := 1 ; -- LineStyle = xlContinuous
c_edge_left CONSTANT NUMBER := 7 ; -- Border = xlEdgeLeft
c_edge_top CONSTANT NUMBER := 8 ; -- Border = xlEdgeTop
c_edge_bottom CONSTANT NUMBER := 9 ; -- Border = xlEdgeBottom
c_edge_right CONSTANT NUMBER := 10 ; -- Border = xlEdgeRight
l_application CLIENT_OLE2.OBJ_TYPE ;
l_workbooks CLIENT_OLE2.OBJ_TYPE ;
l_workbook CLIENT_OLE2.OBJ_TYPE ;
l_worksheets CLIENT_OLE2.OBJ_TYPE ;
l_worksheet CLIENT_OLE2.OBJ_TYPE ;
l_range CLIENT_OLE2.LIST_TYPE ;
PROCEDURE draw_border (
p_range IN CLIENT_OLE2.LIST_TYPE,
p_side IN NUMBER,
p_weight IN NUMBER)
IS
l_edge CLIENT_OLE2.LIST_TYPE ;
l_border CLIENT_OLE2.OBJ_TYPE ;
BEGIN
l_edge := CLIENT_OLE2.CREATE_ARGLIST ;
CLIENT_OLE2.ADD_ARG(l_edge,p_side) ;
l_border := CLIENT_OLE2.GET_OBJ_PROPERTY(l_range,'Borders',l_edge) ;
CLIENT_OLE2.DESTROY_ARGLIST(l_edge) ;
CLIENT_OLE2.SET_PROPERTY(l_border,'LineStyle',c_continuous) ;
CLIENT_OLE2.SET_PROPERTY(l_border,'Weight',p_weight) ;
CLIENT_OLE2.SET_PROPERTY(l_border,'ColorIndex',c_automatic) ;
CLIENT_OLE2.RELEASE_OBJ(l_border) ;
END draw_border ;
BEGIN
l_application := CLIENT_OLE2.CREATE_OBJ('Excel.Application') ;
l_workbooks := CLIENT_OLE2.GET_OBJ_PROPERTY(l_application,'Workbooks') ;
l_workbook := CLIENT_OLE2.GET_OBJ_PROPERTY(l_workbooks,'Add') ;
l_worksheets := CLIENT_OLE2.GET_OBJ_PROPERTY(l_workbook,'Worksheets') ;
l_arguments := CLIENT_OLE2.CREATE_ARGLIST ;
CLIENT_OLE2.ADD_ARG(l_arguments,'Sheet1') ;
l_worksheet := CLIENT_OLE2.GET_OBJ_PROPERTY(l_workbook,'Worksheets',l_arguments) ;
CLIENT_OLE2.DESTROY_ARGLIST(l_arguments) ;
-- Select the box with top-left of A1 and bottom-right of C3.
l_arguments := CLIENT_OLE2.CREATE_ARGLIST ;
CLIENT_OLE2.ADD_ARG(l_arguments,'A1:C3') ;
l_range := CLIENT_OLE2.GET_OBJ_PROPERTY(p_worksheet,'Range',l_arguments) ;
CLIENT_OLE2.DESTROY_ARGLIST(l_arguments) ;
-- Draw border along the left edge of cells in range
draw_border(l_range,c_edge_left,c_thick) ;
-- Draw border along the top edge of cells in range
draw_border(l_range,c_edge_top,c_thick) ;
-- Draw border along the right edge of cells in range
draw_border(l_range,c_edge_right,c_thick) ;
-- Draw border along the bottom edge of cells in range
draw_border(l_range,c_edge_bottom,c_thick) ;
-- Clean up
CLIENT_OLE2.RELEASE_OBJ(l_range) ;
CLIENT_OLE2.RELEASE_OBJ(l_worksheet) ;
CLIENT_OLE2.RELEASE_OBJ(l_worksheets) ;
CLIENT_OLE2.RELEASE_OBJ(l_workbook) ;
CLIENT_OLE2.RELEASE_OBJ(l_workbooks) ;
CLIENT_OLE2.RELEASE_OBJ(l_application) ;
END ;It's worth pointing out that the code above has been culled from my specific procedure and has been simplified. It hasn't been tested, although the DRAW_BORDER nested procedure has been copied straight from working code. -
Resetting the default shape fill to follow the selected forgeround colour - Bug?
Hi guys,
Clean install CS6 - When i choose a shape layer and draw a shape it fills to the colour of my selected foreground colour. This is the way i mostly work.
However i have found if you set the colour fill for the shape layer in the top horizontal context menu, it then will not allow me to revert to my original method of working. I simply cant find a way to use the current foreground colour as a default fill for shapes anymore.
can anyone help me?
cheers
chrisnope.
Basically, the default functionality is FG for shape fill. So say, if i toggle using x it will alteratively create black and white shapes.
If, however i set the colour here (at any time).......
......... it loses that initial functionality and i simply cannot get back to the original behaviour.
I have tried this on 3 colleages machines.
cheers -
TableView selection border color CSS
All how do I change the border colour when you select a table?
Maybe you mean the border applied to the table when the table has focus?
In which case the css below will give the table an indigo border when it is focused.
.table-view:focused { -fx-background-color: indigo,-fx-box-border,-fx-control-inner-background; }Not quite sure what "select" means in this context and if you are interested in the border of the entire table or the border of a selected row.
Anyway, changing those other things is just a matter of tweaking different css styles. -
Numbers v5 Setting custom fill colours
With the loss of the top bar cell and font options the new sidebar inpsector contains a more limited range of standard Colour Fill colours, and most are very strong colours. I would like to use the slightly wider range of colours offered in the previous version of Numbers. Is there any way of adding a few custom colours to this selection. I have set some custom colours in the separate colours dialogue box, but prefer not to have to have this open all the time when the Inspector in open all the time as well
This is also a problem in Pages v5
Any suggestions would be appreciatedHi Emily,
Bring up the Colour window (shift command c).
Step 1. Create a colour (I can't get an arrow or number 1 on top of this screen shot).
Step 2. Your colour will appear as shown by Arrow 2.
Step 3. Drag the colour to the custom palette shown by Arrow 3.
Step 4. Drag from the custom palette to a table cell.
As a test, I Quit Numbers and relaunched. The custom colour was still in the custom palette.
Regards,
Ian.
Edit: Step 3, drag from the colour pane (Arrow 2) to the custom palette (Arrow 3). Ian. -
Tip for quickly selecting contrasting colours?
Hello,
I have a custom brush defined of my signature that I put on my photos. As I want the signature to be subtle so it doesn't detract from the photo, I use a colour that almost blends with the colours in that corner of the photo. The signature is visible, yet it doesn't attract attention.
As examples, the signature would be a shade of green over grass, blue over ocean, grey over asphalt, etc.
Selecting the color to use is trial-and-error, tweaking it several times so it isn't too bright, too dark, or too contrasting with the background. As each photo needs a different colour, this becomes time consuming after hundreds of images.
Is there a tool or other way in PS (either CS2 or CS4) to select a colour like this more quickly? Perhaps one that picks an "average" colour from the area for the signature, and then tunes it a bit brighter or darker so it will show up?
At the moment I an experimenting with using the Eye Dropper, set to 101x101 sample averaging (the largest available). So with the signature brush selected, I Alt-click to get this average colour. But then I still need to make the colour lighter or darker, otherwise the signature blends in too well, almost invisible. Is their a shortcut key way to lighten or darken the selected foreground colour?
Thanks,
KDJThanks all!
I hoped changing the brush or layer blends modes alone might do it. On more-or-less gradual background tones, it sometimes works okay. However on busier backgrounds (like grass!), the signature becomes very speckled as almost each pixel takes on a different colour. Unfortunately the effect makes the sig simultaneously both very conspicuous and impossible to read :D
Ho, interesting tool, though not sure how it fits in within PS to select colour based on one area of the image.
J Maloney, I tried following your steps, though not sure I understand what you meant. For "select thay layer trans", unpainted areas of my layers are transparent by default. Do you mean set Opacity to 0%? Or select the transparent areas of the layer, by ctrl-click the layer icon and then Invert Selection? And what do I select for your second Copy Merged? And why two Copy Merges? Can the blending be set on the first layer instead, and skip one?
The Blur Average step might help with the pixelation mentioned above.
I can see this is going to take some experimenting to make fire-and-forget-automated..., variables such as the starting colour, blend type, etc., need to be robust enough so that a single setting works for all images.
Thanks,
KDJ -
Setting the border when JCombobox get focused
Hello,
Is it possible to set the border when the JCombobox get focused?
In fact, I would like to hide the border at all, but remain the "setFocusable(true)"
Thanks in advance.So why did you post your last three questions in the Swing forum, but then decide to post this "Swing related" question in the Java Programming forum?
Is it possible to set the border when the JCombobox get focused?Try it!
If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area. -
How can I select a colour from the colour 'wheel'
I would like to be able to select a colour like you can in photoshop. The swatches are very limited. I would like to select it from the colour 'wheel', where you can move up and down the slider to select the value and then move over the circle to select your colour? Or where can I find a huge swatch of colours?
Regards
JennyJenny,
How would the Color Picker suit you?
You can DoubleClick the Fill or Stroke (hollow) square in the Toolbox or the Color palette. -
How to set selected file in FileChooser showSaveDialog to default file name
Hi,
How do I set selected file in JavaFX 2.0 FileChooser showSaveDialog, so I can prompt the user with a suggested default file name?
I am converting a Java Swing application I wrote a few years ago to JavaFX 2.0.
In the Swing application, I use setSelectedFile() as follows:
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setSelectedFile(new File(backupfile));
jFileChooser.setCurrentDirectory(new File(outputDirectory));
FileFilter filter = new FileNameExtensionFilter("Comma Delimited (*.csv)", "csv");
jFileChooser.addChoosableFileFilter(filter);
jFileChooser.setFileFilter(filter);
filter = new FileNameExtensionFilter("XML Document (*.xml)", "xml");
jFileChooser.addChoosableFileFilter(filter);
jFileChooser.setAcceptAllFileFilterUsed(false);
jFileChooser.setDialogTitle("Export File");
int returnVal = jFileChooser.showDialog(jFrame, "Export");
This would show a file chooser with the file name text field pre-populated with a default backup file name.
I can't find an equivalent in JavaFX.
Also, in the Swing application, I was able to determine which extension filter was selected at run time using getFileFilter().getDescription() as follows:
String extension = jFileChooser.getFileFilter().getDescription();
if (extension.equals("XML Document (*.xml)")) { ...
I can't find an equivalent in JavaFX.
Thanks,
BarryYou can use the open sequence file method on the application manager (then you only need to wire the file path)
Rodéric L
Certified LabVIEW Architect -
How to set a default colour & thickness for rectangle in preview?
How to set a default colour & thickness for rectangle(annotation) in preview ? Because every time that I choose for example red and thickness 1 it reverts to orange and 3 next time .
Doesn't appear to be a default setting. Peruse the webpage for Secrets at http://secrets.blacktree.com/ for a possible setting.
-
TDMS : How to set the background colour programatically for .tdms file
Hello every one
is there any method to set the background colour of .tdms file programatically
Thank you
RajaHi Raja,
"TDMS" is a file on your harddisc. How should a file have a background color?
Or the other way around:
How do you set the background color of a simple text file?
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
How to set the border of header of JTable
I am using the following code to set the border of my JTable headers but it doesn't seem to work!! The headers do get CENTER aligned but somehow they do not show the right border. Please Help.
class cellAlignRenderer extends DefaultTableCellRenderer
cellAlignRenderer()
setHorizontalAlignment(JLabel.CENTER);
Border b = BorderFactory.createEtchedBorder() ;
setBorder(b);
jTable.getColumn(0).setHeaderRenderer( new cellAlignRenderer());try this
public class YourTableHeaderRenderer extends DefaultTableCellRenderer
public YourTableHeaderRenderer()
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
JLabel comp = (JLabel) super.getTableCellRendererComponent(table,value,
isSelected,hasFocus,row,column);
try
comp.setBorder(BorderFactory.createBevelBorder(0,Color.lightGray,Color.darkGray));
setFont(new java.awt.Font("Dialog", 0, 15));
setHorizontalAlignment(SwingConstants.CENTER);
catch(Exception err)
err.printStackTrace();
return this; -
Selecting with colour range doesn't work properly
Well, at least to me it doesn't work properly. If I have elements on seperate levels and I use the colour range option to select the area, it works on all the levels, not just the level I have selected. That's not what I want! I only want it to select the colour range on that one level. The work around is to manually turn off other levels, but on a file with lots of levels, that can be tedious. Can this be avoided? Incidentally, magic wand works only on the selected level, but not colour range (or color range, if you are American).
Aha! You are correct. Layers above the target layer are still being sampled when sampling is at "Current Layer".
That has to be a bug. The Eye Dropper Tool itself does work correctly, though.
I'm about to report another problem, so I'll report this one, too.
Edit: Looking again, I don't think there is a bug.
It seems to not be that the higher layer is seen when sampling "Current Layer", which is correct and the same as when the Eye Dropper Tool itself is use. However, the pixels of the visible composite are then evaluated to determine the regions to be selected. I guess that's correct behaviour and you will have to do the Alt-click on eye trick to completely ignore all other layers.
Maybe you are looking for
-
Completely stuck, get/set, Contructors and Static Methods
Hi any help would be very appreciated on this one, import java.util.Scanner; import java.io.*;* *import java.util.*; public class Course extends Program { public Course(String Coursecode, String Coursename){ Coursecode = stuinput.cours
-
Importing vm created on vm server in vm manager
Hi all, I have created a vm with virt-install on the vm server.This only created a hardisk image file at the location which i specified as /OVS/running_pool/vm_name and one configuration file in /etc/xen. when i try to import this vm in the vm manage
-
How can I change my apple registry to Canadian from US?
I received my ipod while in the US and set it up there so I could use it for the months before I went home to Canada. But now at home I cannot access any Canadian apps ( like my bank) because it's a 'US' ipod. How can I change the apple registry to r
-
What is the procedure to sync Outlook 2011 Contacts, Calendars, Notes, and Tasks to my iPhone4S using OS X Version 10.8.3?
-
Urgent Hypanalyzer installatin 7.2.5.5
Hi , We got a issue while installing hyp analayzer , we installed on two machines, for some reason on one machine analyzer server is not starting It is throwing me a dialog Windows cannot find "-Xms128m" make sure you typed them correnctly"" , When I