我试过用:
frame1.getContentPane().setBackground(Color.yellow);
Run Code Online (Sandbox Code Playgroud)
但它没有用.谁能帮我?
import java.awt.*;
import java.awt.Color;
public class PlayGame {
public static void main(String[] args) {
GameFrame frame1 = new GameFrame();
frame1.getContentPane().setBackground(Color.yellow);
// Set Icon
Image icon = Toolkit.getDefaultToolkit().getImage("image/poker_icon.gif");
frame1.setIconImage(icon);
frame1.setVisible(true);
frame1.setSize(600, 700);
frame1.setTitle("Card Game");
// Set to exit on close
frame1.setDefaultCloseOperation(GameFrame.EXIT_ON_CLOSE);
}
}
Run Code Online (Sandbox Code Playgroud)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GameFrame extends JFrame implements ActionListener {
private JPanel topPnl, btmPnl, pcPnl, mainPnl;
private JPanel titlePnl, playerPnl, computerPnl;
private JLabel titleLbl, playerLbl, computerLbl;
private JLabel testTextBox1, testTextBox2; …Run Code Online (Sandbox Code Playgroud) 在设置视图的背景颜色时,有没有办法获得渐变效果或半透明效果?例如,这段代码:
selView.setBackgroundColor(Color.rgb(240, 128, 128)); // light red
Run Code Online (Sandbox Code Playgroud)
突出显示列表视图中的选定视图.渐变或背景都很酷.
我想为ImageView设置背景颜色,当imageview有图像资源时,它可以工作,我得到我的背景颜色但是当图像视图没有图像资源时,SetBackgroundColor不起作用,什么都不做,这是我的代码:
xml布局:
<ImageView android:layout_centerHorizontal="true"
android:id="@+id/favor_item_image"
android:layout_alignParentTop="true" android:layout_height="wrap_content"
android:layout_width="match_parent" android:adjustViewBounds="true"/>
Run Code Online (Sandbox Code Playgroud)
java代码:
ImageView favorImage = (ImageView) MyView.findViewById(R.id.favor_item_image);
//favorImage.setImageResource(R.drawable.btndelete);
favorImage.setBackgroundColor(Color.argb(255,255,0,0));
Run Code Online (Sandbox Code Playgroud)
所以,当我评论这一行://favorImage.setImageResource(R.drawable.btndelete); 我无法设置图像视图背景颜色,但是当我取消注释这一行时,setBackgroundColor工作正常.
请帮忙.谢谢
我正在编写JFrame表单中的可编辑组合框,但我想改变背景颜色.
程序如何工作:如果我点击"按"按钮,那么组合框的背景需要变成黑色.
我试过了:
1.
cbo.setBackground(Color.BLACK);
Run Code Online (Sandbox Code Playgroud)
但它没有做任何事情
2
cbo.getEditor().getEditorComponent().setBackground(Color.BLACK);
((JTextField) cbo.getEditor().getEditorComponent()).setOpaque(true);
Run Code Online (Sandbox Code Playgroud)
做这个:

代码示例:
public class NewJFrame extends javax.swing.JFrame {
private JComboBox cboCategorie;
public NewJFrame() {
initComponents();
cboCategorie = new JComboBox();
cboCategorie.setBounds(10, 10, 250, 26);
cboCategorie.setVisible(true);
cboCategorie.setEditable(true);
this.add(cboCategorie);
}
private void pressActionPerformed(java.awt.event.ActionEvent evt) {
cboCategorie.getEditor().getEditorComponent().setBackground(Color.BLACK);
((JTextField) cboCategorie.getEditor().getEditorComponent()).setOpaque(true);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Java JDK7
任何sugestions?
我有两个类文件:
屏幕https://gist.github.com/3020101
JMain https://gist.github.com/3020107
我试图让它全屏显示5秒并显示背景(或者,此时,甚至是前景)但是当我运行它时全屏显示5秒钟,但是它只是一个空白的浅灰色屏幕.
我究竟做错了什么?最终我将使用图像作为背景,我想确保我没有搞砸到某个地方.
多谢你们!
编辑:当我在我的JMain类的末尾添加它时,字体颜色与前景色相同,但无论我在程序中将其更改为什么颜色,背景总是黑色.
public void paint(Graphics g) {
g.drawString("This is gonna be awesome", 200, 200);
}
Run Code Online (Sandbox Code Playgroud)
来自github的代码
import java.awt.*;
import javax.swing.JFrame;
public class JMain extends JFrame {
private JFrame frame = new JFrame();
public static void main(String[] args) {
DisplayMode dm = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
JMain m = new JMain();
m.run(dm);
}
public void run(DisplayMode dm) {
this.getContentPane().setBackground(Color.RED);
frame.setForeground(Color.BLACK);
frame.setFont(new Font("Arial", Font.PLAIN, 24));
Screen s = new Screen();
try {
s.setFullScreen(dm, this); …Run Code Online (Sandbox Code Playgroud) import javax.swing.JApplet;
import java.awt.*;
public class Snowman extends JApplet {
//---------------------------------------------
// Draws a snowman.
//---------------------------------------------
public void paint (Graphics page)
{
final int MID = 150;
final int TOP = 50;
setBackground (Color.cyan);
page.setColor(Color.blue);
page.fillRect(0, 175, 300, 50); // ground
page.setColor (Color.yellow);
page.fillOval (-40, -40, 80, 80); // sun
page.setColor (Color.white);
page.fillOval (MID-20, TOP, 40, 40); // head
page.fillOval (MID-35, TOP+35, 70, 50); // upper torso
page.fillOval (MID-50, TOP+80, 100, 60); // lower torso
page.setColor (Color.black);
page.fillOval(MID-10, TOP+10, 5, …Run Code Online (Sandbox Code Playgroud) 基本上我想要做的是,使用图像的url(无论是否下载都无关紧要)来设置relativelayout的背景
我用Google搜索了几个小时并尝试了很多建议,但我总是遇到错误和应用程序崩溃...
if((!modelsArrayList.get(position).isGroupHeader())&& (modelsArrayList.get(position).isProfBox())) {
rowView = inflater.inflate(R.layout.prof_header, parent, false);
TextView titleView = (TextView) rowView.findViewById(R.id.header);
titleView.setText(modelsArrayList.get(position).getTitle());
RelativeLayout rLayout=(RelativeLayout)rowView.findViewById(R.id.ProfHead);
rLayout.setBackgroundResource("HTTP://URL.HERE");
Run Code Online (Sandbox Code Playgroud)
我试过这样的人(http://looksok.wordpress.com/2013/07/06/android-tutorial-download-image-from-the-internet-with-url/),但它没有用