「java给图片加边框」js给图片加边框

博主:adminadmin 2023-01-12 00:21:19 507

本篇文章给大家谈谈java给图片加边框,以及js给图片加边框对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java图形用户界面中对话框的背景图片覆盖了文本框和按钮,咋办呢???

对话框上GDI+画的JPG图片作为背景

上面有一个自绘按钮

刚启动的时候还好

有些操作 比如把窗口拖着多晃两下

按钮和图片上面的字就不见了

直到把鼠标放在按钮的那个地方点一个

按钮才出来

这个问题应该怎么解决

总感觉是不是GDI+画图的问题

要是不行还有什么更好的方法实现如下要求

JPG要从文件中读取

设置为对话框的背景

可以通过加载不同的JPG文件更改背景

背景上面有自绘控件和显示文字的静态控件

java的swing中,我想在JComboBox下拉框中添加带图片的文本内容,该如何去实现?

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

/*

* CustomComboBoxDemo.java 你要有下列文件

* images/Bird.gif

* images/Cat.gif

* images/Dog.gif

* images/Rabbit.gif

* images/Pig.gif

*/

public class CustomComboBoxDemo extends JPanel {

ImageIcon[] images;

String[] petStrings = {"Bird", "Cat", "Dog", "Rabbit", "Pig"};

/*

* Despite its use of EmptyBorder, this panel makes a fine content

* pane because the empty border just increases the panel's size

* and is "painted" on top of the panel's normal background. In

* other words, the JPanel fills its entire background if it's

* opaque (which it is by default); adding a border doesn't change

* that.

*/

public CustomComboBoxDemo() {

super(new BorderLayout());

//Load the pet images and create an array of indexes.

images = new ImageIcon[petStrings.length];

Integer[] intArray = new Integer[petStrings.length];

for (int i = 0; i petStrings.length; i++) {

intArray[i] = new Integer(i);

images[i] = createImageIcon("images/" + petStrings[i] + ".gif");

if (images[i] != null) {

images[i].setDescription(petStrings[i]);

}

}

//Create the combo box.

JComboBox petList = new JComboBox(intArray);

ComboBoxRenderer renderer= new ComboBoxRenderer();

renderer.setPreferredSize(new Dimension(200, 130));

petList.setRenderer(renderer);

petList.setMaximumRowCount(3);

//Lay out the demo.

add(petList, BorderLayout.PAGE_START);

setBorder(BorderFactory.createEmptyBorder(20,20,20,20));

}

/** Returns an ImageIcon, or null if the path was invalid. */

protected static ImageIcon createImageIcon(String path) {

java.net.URL imgURL = CustomComboBoxDemo.class.getResource(path);

if (imgURL != null) {

return new ImageIcon(imgURL);

} else {

System.err.println("Couldn't find file: " + path);

return null;

}

}

/**

* Create the GUI and show it. For thread safety,

* this method should be invoked from the

* event-dispatching thread.

*/

private static void createAndShowGUI() {

//Create and set up the window.

JFrame frame = new JFrame("CustomComboBoxDemo");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.

JComponent newContentPane = new CustomComboBoxDemo();

newContentPane.setOpaque(true); //content panes must be opaque

frame.setContentPane(newContentPane);

//Display the window.

frame.pack();

frame.setVisible(true);

}

public static void main(String[] args) {

//Schedule a job for the event-dispatching thread:

//creating and showing this application's GUI.

javax.swing.SwingUtilities.invokeLater(new Runnable() {

public void run() {

createAndShowGUI();

}

});

}

class ComboBoxRenderer extends JLabel

implements ListCellRenderer {

private Font uhOhFont;

public ComboBoxRenderer() {

setOpaque(true);

setHorizontalAlignment(CENTER);

setVerticalAlignment(CENTER);

}

/*

* This method finds the image and text corresponding

* to the selected value and returns the label, set up

* to display the text and image.

*/

public Component getListCellRendererComponent(

JList list,

Object value,

int index,

boolean isSelected,

boolean cellHasFocus) {

//Get the selected index. (The index param isn't

//always valid, so just use the value.)

int selectedIndex = ((Integer)value).intValue();

if (isSelected) {

setBackground(list.getSelectionBackground());

setForeground(list.getSelectionForeground());

} else {

setBackground(list.getBackground());

setForeground(list.getForeground());

}

//Set the icon and text. If icon was null, say so.

ImageIcon icon = images[selectedIndex];

String pet = petStrings[selectedIndex];

setIcon(icon);

if (icon != null) {

setText(pet);

setFont(list.getFont());

} else {

setUhOhText(pet + " (no image available)",

list.getFont());

}

return this;

}

//Set the font and text when no image was found.

protected void setUhOhText(String uhOhText, Font normalFont) {

if (uhOhFont == null) { //lazily create this font

uhOhFont = normalFont.deriveFont(Font.ITALIC);

}

setFont(uhOhFont);

setText(uhOhText);

}

}

}

JAVA如何设置窗体的形状

设置窗体没有边框(没有最小化,最大化,便闭按钮),然后设置背景图片,让背景颜色和图片底色一致,这样窗体就和图片一样的形状了

急急急!!!html如何实现在图片上添加文本输入框????

写一个div,css,id样式中写#div {background:url("img.jpg") no-repeat;}可用background-position来控制背景图片的位置,form也用div框起来,用样式控制,如margin和padding(都有上下左右)或是空格nbsp;(html中代表空格)。框框的颜色属性就难了。我以自己知识还解决不了,高手上吧。

关于java给图片加边框和js给图片加边框的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。