jjzjj

setBackground

全部标签

Java KeyBindings 组合不起作用

我正在努力创建一种识别组合键的方法。在我设置任何boolean值之前,我注意到某些组合键会导致忽略其他键。packagequestion;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Dimension;importjava.awt.event.ActionEvent;importjava.awt.event.KeyEvent;importjavax.swing.AbstractAction;importjavax.swing.JComponent;importjavax.swing.JFrame;imp

java - 设置背景(新颜色());在 Java 中不理解给定的 RGB 值

我有一个带有一些gui的程序,在我设置的JFrame上,setBackground(newColor(107,106,104));问题是我得到的是灰色,但不是正确的颜色。如果我在PhotoShop中检查它,它会给我RGB值(126,125,123)附言。我用十六进制值试过,结果一样。 最佳答案 Ihaveaprogramwithsomegui,ontheJFrameIset,setBackground(newColor(107,106,104));[Theproblem]Itgivesagreyishcolor,butnotther

java - JTable 将单元格颜色设置为特定值

我正在尝试编写一种方法,针对给定的参数(值、颜色),在值等于cellValue的单元格的背景上设置颜色。我的方法实际做的是,它在整行单元格的背景上设置颜色,当我选择表格中的行时,我希望方法只在特定列设置颜色(其中cellValue等于value)每次调用该方法时。voidsetCellBackgroundColor(booleancellValue,finalColorcolor){List>data=tView.getTTableModel().getData();for(introw=0;row 最佳答案 whenIselect

java - JPanel setBackground(Color.BLACK) 什么都不做

我有以下自定义JPanel,我已使用NetbeansGUI构建器将它添加到我的框架中,但背景不会改变!我可以看到圆圈,用g.fillOval()绘制。怎么了?publicclassBoardextendsJPanel{privatePlayerplayer;publicBoard(){setOpaque(false);setBackground(Color.BLACK);}publicvoidpaintComponent(Graphicsg){super.paintComponent(g);g.setColor(Color.red);g.fillOval(player.getxCent

android - View.setBackground 抛出 NoSuchMethodError

这个问题在这里已经有了答案:setBackgroundvssetBackgroundDrawable(Android)(12个答案)关闭9年前。以下代码:Viewinflate=inflater.inflate(R.layout.page,null);Drawableimg=getResources().getDrawable((Integer)(item.get("img")));inflate.findViewById(R.id.page_img).setBackground(img);产生以下错误:java.lang.NoSuchMethodError:android.view.

Android如何在setBackgroundColor上获得渐变效果

有没有办法在设置View的背景色时得到渐变效果或半透明效果?例如,这段代码:selView.setBackgroundColor(Color.rgb(240,128,128));//lightred突出显示ListView中的选定View。渐变或背景都会很酷。 最佳答案 您首先需要在xml中创建一个渐变。您应该将其添加到您的一个drawables.xml中。然后您应该能够将它应用到xml中的ListView。android:background=@drawable/yourdrawable或setBackgroundResource

android - setBackgroundResource 的行为不同于 setBackground with RippleDrawable

我正在尝试将RippleDrawable设置为ListView行的背景。使用view.setBackgroundResource(R.drawable.ripple)时一切正常。尝试时view.setBackground(view.getContext().getDrawable(R.drawable.ripple))它可以工作,但是当快速触摸该项目时不会显示波纹(我也有该项目的激活/选中状态),只有当我按住View时它才会出现。View类中的setBackgroundResource方法如下所示:if(resid!=0&&resid==mBackgroundResource){ret

android - getView 中的自定义 ArrayAdapter setBackground

我正在开发一个ListActivity,它将显示一堆数字(权重)。我想更改ListView中特定行的背景。为此,我创建了ArrayAdapter类的自定义实现并覆盖了getView方法。适配器接受数字列表并将数字为20的行的背景设置为黄色(为简单起见)。publicclassWeightListAdapterextendsArrayAdapter{privateListmWeights;publicWeightListAdapter(Contextcontext,Listobjects){super(context,android.R.layout.simple_list_item_1

android - 如何将 setBackground 与 Android 小部件一起使用

我之前问过类似的问题,但是我的要求太含糊了。下面的代码绘制了一个漂亮的程式化按钮。当你点击按钮时,你可以输入一个数字,并根据数字,使用改变背景颜色remoteViews.setInt(R.id.nmcButton,"setBackgroundColor",color);不幸的是,当我尝试使用来保留样式时remoteViews.setInt(R.id.nmcButton,"setBackground",color);小部件不会加载。有没有解决的办法?有没有办法在更改背景颜色的同时保留样式?这里是一些相关的文件packagetest.widget;importandroid.os.Bund

android - android 上 setBackgroundDrawable 的解决方法?

AndroidSDKAPI级别16中的View类的setBackgroundDrawable()方法现已弃用。新方法是setBackground()但当然它只在API16中可用。如果我希望我的应用程序与以前的API级别兼容,我该如何解决这个问题?(至少API14)目标是消除任何警告,@SupressWarnings不是我的解决方案。 最佳答案 通常的做法是这样的:if(android.os.Build.VERSION.SDK_INT>=16)setBackground(...);elsesetBackgroundDrawable(.